【问题标题】:Touches - User interaction of parent and childTouches - 父母和孩子的用户交互
【发布时间】:2011-12-23 23:27:16
【问题描述】:
我有一个关于 Touches 的问题,但可能有几个人遇到过。
我有一个视图,上面有一些标签和图像视图。如果我通过禁用用户交互来禁用我的视图的触摸,那么所有子视图的所有触摸都将被禁用,如果我可能希望在禁用视图的用户交互时启用一些触摸并禁用一些触摸。
这是唯一的解决方案:创建两个单独的视图,其中一个将启用用户交互,而其他用户将被禁用并在其上实现我的东西?
问候,
雷诺·琼斯
【问题讨论】:
标签:
iphone
objective-c
ios
ios4
ios5
【解决方案1】:
通常 UILabel 和 UIImageView 默认没有触摸事件。所以你只需要在你想要的地方启用触摸事件。
我强烈建议使用这样的 UIButton:
- (void)viewDidLoad {
UIButton *buttonActionA = [[UIButton alloc] initWithFrame:CGRectMake(50.0, 50.0, 100.0, 100.0)];
[buttonActionA addTarget:self action:@selector(doActionA) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonActionA];
[buttonActionA release];
}
- (void) doActionA {
NSLog(@"This is Action A");
}
并避免子类化 UIView 只是为了实现
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
这回答了你的问题吗?