- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
container = [[UIView alloc] initWithFrame:self.view.frame];
UIImageView* main_im0 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon1.png"]];
[container addSubview:main_im0];
[self.view addSubview:container];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *tt = [touches anyObject];
UIImageView *touchedview=(UIImageView*)[tt view];
NSArray *views = [container subviews];
for (UIImageView* im in views)
{
UIImageView* focus=im;
if (touchedview==focus)
{
}
}
}
我有一段代码来设置名为main_im0的ImageView,将其放入UIView容器中,然后将其放入视图中。当我按一下main_im0时,我期望触摸功能会达到touchedview == focus的条件。但是,我无法激活该条件?怎么了?
最佳答案
请启用
main_im0.userInteractionEnabled = YES;
默认情况下,它是
No
的UIImageView
关于ios - iOS接触UIImageView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11981863/