我的UIView
包含UIScrollView
。
这个UIView
应该响应一些触摸事件但由于它包含的scrollView没有响应。
此scrollView的contentView
设置为OuterView内的MoviePlayer。
现在每当我点击MoviePlayer所在的区域时,我的OuterView的触摸事件都没有响应。
我甚至将电影播放器的userInteraction
设置为NO
。
但现在看来scrollView正在干扰。
我已经在SO上提到了这篇文章。
How can a superview interecept a touch sequence before any of its subviews?
但是那里的解决方案要求我为scrollView设置userInteractionEnabled
到NO
但如果我这样做,我的捏缩放也不会发生!
怎么办?
答案 0 :(得分:0)
UIScrollView拦截所有触摸事件,因为它必须决定用户是否/何时移动他们的手指以滚动滚动视图。 您可能想要继承UIView,然后在
中- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;
方法,检查必要的触摸,然后将所有这些方法转发到UIScrollViewInstance。例如:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface MyView: UIView {
UIScrollView *scrollView;
}
@end
@implementation MyView
/* don't forget to alloc init your ScrollView init -init
and release it in -dealloc! Then add it as a subview of self. */
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt
{
/* check for a gesture */
[scrollView touchesBegan:touches withEvent:evt];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
{
/* check for a gesture */
[scrollView touchesMoved:touches withEvent:evt];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;
{
/* check for a gesture */
[scrollView touchesEnded:touches withEvent:evt];
}
@end