Avi*_*dok 6 objective-c uiscrollview hittest ios
无法找到解决方案.
我正在构建一个具有大滚动视图的应用程序,具有分页(水平).在这个滚动视图中,有一个UIView网格,每个网格中都有一个UIScrollview,有垂直滚动视图.
现在,关键是,当我分页我的'大'滚动视图时,有时触摸会卡在网格的UIViews中的一个小滚动视图中.
我不知道如何避免它 - 尝试使用hitTest但仍然无法找到答案.
希望我很清楚......
谢谢你的帮助.
编辑:
这是更大的scrollview:
@implementation UIGridScrollView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
self.pagingEnabled;
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
现在,对于这个UIGridScroll View,我添加了一个子视图这个视图:
@implementation UINoteView
{
IBOutlet UIScrollView *_innerScrollView; // this scrollview frame is in the size of the all UINoteView
}
- (void)awakeFromNib
{
_innerScrollView.contentSize = CGSizeMake(_innerScrollView.frame.size.width, _innerScrollView.frame.size.height+50.0f);
}
@end
Run Code Online (Sandbox Code Playgroud)
分页效果很好,内部滚动视图效果很好,但是当我分页较大的音符视图时,我的手指"卡在"_innerScrollView中的次数太多了.
谢谢!
您可以子类化UIScrollView
并实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
,允许滚动视图的内置功能panGestureRecognizer
与另一个滚动视图的手势识别器同时识别。
例子:
//This is needed because the public UIScrollView headers
//don't declare the UIGestureRecognizerDelegate protocol:
@interface UIScrollView (GestureRecognition) <UIGestureRecognizerDelegate>
@end
@interface MyScrollView : UIScrollView
@end
@implementation MyScrollView
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (gestureRecognizer == self.panGestureRecognizer) {
return YES;
} else if ([UIScrollView instancesRespondToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) {
//Note: UIScrollView currently doesn't implement this method, but this may change...
return [super gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
}
return NO; //the default
}
@end
Run Code Online (Sandbox Code Playgroud)
对于水平或所有垂直滚动视图使用此子类就足够了。
在尝试以这种方式使用默认行为后,您实际上可能会发现自己更喜欢它。允许两个视图同时滚动几乎总是会导致左右滑动时意外的垂直滚动,这可能会令人恼火(大多数人不会做完美的水平滑动手势)。
归档时间: |
|
查看次数: |
4864 次 |
最近记录: |