How to scroll through actions in alert controller? Xcode 8, Swift 3, IOS

前端 未结 3 683
北海茫月
北海茫月 2021-01-27 04:11

Please help! :) Im a huge noobie here. I\'ve gathered this code from various sources so i don\'t really know what I\'m doing. My alert controller displays a textfield that I can

3条回答
  •  自闭症患者
    2021-01-27 04:57

    This finds the scrollView and scrolls to the top. We search all subviews because more than one subview responds to setContentOffset, but don't bother checking which one.

    - (void)methodThatCreatesTheAlertController
    {
        // make the alertController here, add actions, and then...
    
        [self presentViewController:alertController animated:YES completion:^{
            [self scrollToTopOfAlertControllerView:alertController.view];
        }];
    
    }
    
    - (void)scrollToTopOfAlertControllerView:(UIView *)view
    {
        for ( UIView *aSubview in view.subviews ) {
            if ( [aSubview respondsToSelector:@selector(setContentOffset:animated:)] ) {
                // _UIInterfaceActionGroupHeaderScrollView
                // _UIInterfaceActionRepresentationsSequenceView <-- this is the one that scrolls
                [((UIScrollView *)aSubview) setContentOffset:CGPointZero animated:YES];
            }
            [self scrollToTopOfAlertControllerView:aSubview]; // recurse
        }
    }
    

提交回复
热议问题