思路
git
自定義一個view,view 裏面封裝了一個 scrollview,scrollview 的寬度等於你須要的那個滾動子控件寬度。github
scrollview的clipsToBounds = NO; 讓裏面的內容超出scrollview 的大小spa
自定義view 的clipsToBounds = YES;ip
4.實現get
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {源碼
UIView *view = [super hitTest:point withEvent:event];it
if ([view isEqual:self])event
{cli
for (UIView *subview in scrollview.subviews)scroll
{
CGPoint offset = CGPointMake(point.x - scrollview.frame.origin.x + scrollview.contentOffset.x - subview.frame.origin.x,
point.y - scrollview.frame.origin.y + scrollview.contentOffset.y - subview.frame.origin.y);
if ((view = [subview hitTest:offset withEvent:event]))
{
return view;
}
}
return scrollview;
}
return view;
}
源碼地址在