ScrollView分页滑动1/3
滑动后效果
首先要创建个uiview 在初始化initWithFrame方法中加上UIScrollView视图 上代码
scrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,0,[selfbounds].size.width/3,40)];
scrollView.clipsToBounds = NO;
[scrollView setPagingEnabled:YES];
scrollView.scrollEnabled = YES;
scrollView.delegate = self;
[scrollView setContentSize:CGSizeMake(6*(self.frame.size.width/3), 40)];
[scrollView setShowsHorizontalScrollIndicator:NO];
然后在scrollView上面放想要的视图
然后关键点在下面
重写hitTest方法
- (UIView *) hitTest:(CGPoint) point withEvent:(UIEvent *)event {
if ([self pointInside:point withEvent:event]) {
return scrollView;
}
returnnil;
}