[英]ScrollView with Paging
I have added 3 UIViewController
in my ScrollView , like this 我在ScrollView中添加了3个UIViewController
,就像这样
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"view1"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"view2"]];
[self addChildViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"view3"]];
How can i find which is visible ? 我如何找到可见的?
You only use - (void)addChildViewController:(UIViewController *)childController
to build your own containment view controller (eg your own tabBarController), not to add a subview to a scrollview. 您只能使用- (void)addChildViewController:(UIViewController *)childController
来构建自己的包含视图控制器(例如,您自己的tabBarController),而不是将子视图添加到滚动视图。 For more information on view controller containment you should read https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html and for a short summary you could read When to use addChildViewController vs pushViewController 有关视图控制器包含的更多信息,您应该阅读https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html ,有关简短摘要,您可以阅读何时使用addChildViewController和pushViewController
If you want to add a view to a scrollview, you should simply use - (void)addSubview:(UIView *)view
(eg [self.scrollView addSubview:viewOfViewControllerWithIdentifierView1]
). 如果要向滚动视图添加视图,则只需使用- (void)addSubview:(UIView *)view
(例如[self.scrollView addSubview:viewOfViewControllerWithIdentifierView1]
)。 Also make sure you set the scrollviews contentSize and the subviews frame. 还要确保设置了scrollviews contentSize和subviews框架。 However, if you want a scrollview to page between different view controllers, I'd recommend you take a look at UIPageViewController: https://developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html 但是,如果要在不同的视图控制器之间滚动到页面,则建议您看一下UIPageViewController: https : //developer.apple.com/library/ios/documentation/uikit/reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html
You can check this by the calculating the contentoffset of you scroll view. 您可以通过计算滚动视图的contentoffset进行检查。 For this You have to add the Delegate Methode of Scrollview. 为此,您必须添加Scrollview的Delegate Methode。
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
page_control.currentPage=scrollView.contentOffset.x/320;
}
In above code I have multiple ChildView controller having Width of 320px means complete iPhone screen width. 在上面的代码中,我有多个宽度为320像素的ChildView控制器,表示完整的iPhone屏幕宽度。 And page_control is the Page Controller for Which I'm selecting the current Page. page_control是要为其选择当前页面的页面控制器。
Let me ask If you have any confusion. 让我问您是否有任何困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.