我正在尝试在预安装的滚动视图类上添加一个pageviewcontroller,以创建一个很好的效果。以下是他们安装scrollview的方法:
- (void)setTitleArray:(NSArray *)titleArray {
titlesArray = titleArray;
arrayCount = titleArray.count;
self.topTab.frame = CGRectMake(0, 20, FUll_VIEW_WIDTH, PageBtn+20);
self.scrollView.frame = CGRectMake(0, PageBtn+20, FUll_VIEW_WIDTH, FUll_VIEW_HEIGHT - PageBtn - TabbarHeight);
[self addSubview:self.topTab];
[self addSubview:self.scrollView];
}
- (UIScrollView *)scrollView {
if (!_scrollView) {
_scrollView = [[UIScrollView alloc] init];
_scrollView.delegate = self;
_scrollView.tag = 318;
_scrollView.backgroundColor = UIColorFromRGB(0xfafafa);
_scrollView.contentSize = CGSizeMake(FUll_VIEW_WIDTH * titlesArray.count, 0);
_scrollView.pagingEnabled = YES;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.alwaysBounceHorizontal = YES;
}
return _scrollView;
}
我基于本教程在pageviewcontroller上创建了一个完整的类:http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
然后我尝试在预安装的类中实现它。对于普通视图控制器,它基本上将其视图作为子视图添加到scrollview上。因此我修改了它的方法:
if (class && viewAlloc[i] == NO) {
if([className containsString:@"VC1"]){
UIPageViewController *ctrl = class.new;
ctrl.view.frame = CGRectMake(FUll_VIEW_WIDTH * i, 0, FUll_VIEW_WIDTH, FUll_CONTENT_HEIGHT - PageBtn);
[pagerView addSubview:ctrl];
viewAlloc[i] = YES;
}
else{
UIViewController *ctrl = class.new;
ctrl.view.frame = CGRectMake(FUll_VIEW_WIDTH * i, 0, FUll_VIEW_WIDTH, FUll_CONTENT_HEIGHT - PageBtn);
[pagerView.scrollView addSubview:ctrl.view];
viewAlloc[i] = YES;
}
}
但是以下效果是这样的,我只能滚动水平滚动视图,而不能滚动页面控件。我甚至无法通过触摸点来改变页面。 enter image description here