将触摸转移到父视图,而不禁用子视图的用户交互
我在视图控制器的视图上有一个UIView。 平移手势被添加到UIView上。 现在我想将触摸转移到父视图(视图控制器的视图),以便触摸委托方法也被称为父视图以及UIView也被平移。
取决于你想做什么。 如果你想让视图控制器知道在UIView子中发生了什么,你应该把主视图控制器的委托传递给子视图(面向对象的编程方式)。 像这样的东西:
// in child UIVIew ... id<mainControllerDelegate> _mainControllerDel; // This delegate was passed to the view by the main view controller ... -(void)gestureHappened { [_mainControllerDel gestureHappenedInView]; }
但是,如果您希望两个视图都对手势做出反应,则应使用shouldRecognizeSimultaneouslyWithGestureRecognizer手势委托方法,如下所示:
// In class that conforms to your UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; }
编辑:
我刚刚读过你想要touchesBegan
(和类似的)在父母中调用的方法。 这不是任何UI的标准行为。 请阅读iOS事件应答链 。 如果你真的想要链中的下一个视图被调用,你可以覆盖子的方法并调用下一个响应者。 喜欢这个:
// in child view -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event]; [self.nextResponder touchesBegan:touches withEvent:event]; }
我会做的是类似的,但使用委托:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [_mainControllerDel touchBeganOnView: self withEvent: event]; }
- 应用程序处于后台时未收到后台提取远程通知,并且用户未通过推送通知进入
- 将可滚动button添加到滚动视图
- :hover状态不会在iOS上结束
- 在SpriteKit游戏中拖动拖动
- 没有具有有效签名身份的配置文件。找不到匹配的配置文件,xcode,ios
- video压缩ios:使用AVAssetWriter缩小video的大小
- 在Open ES iPhone应用程序中围绕VBO使用VAO在调用glDrawElements时导致EXC_BAD_ACCESS
- 发布后在connectionDidFinishLoading:,NSURLConnection委托方法内不能收到通知
- 是否可以在iOS智能横幅中使用LinkShare签名?