这对我有用:
(在xib或storyboard中链接子视图)
ViewController.h
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIView *subview;
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
@implementation ViewController
@synthesize subview;
@synthesize tapRecognizer;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
[subview addGestureRecognizer:tapRecognizer];
}
- (IBAction)handleTap:(UITapGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded){
//code here
NSLog(@"subview touched");
}
}
@end
Run Code Online (Sandbox Code Playgroud)
问题已经解决了.我觉得有人给了一个很好的答案,但我忘记了.
这就是我做的.XIB中有一个选项.有一个复选框(标题为"启用了用户交互"),指定子视图是否处理用户事件.
取消选中该复选框,并且所有触摸子视图都会转到父视图或其后的任何其他视图.
| 归档时间: |
|
| 查看次数: |
14717 次 |
| 最近记录: |