gpt4 book ai didi

iOS 触摸 UIImageView

转载 作者:行者123 更新时间:2023-11-28 18:40:05 29 4
gpt4 key购买 nike

  - (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 容器中,然后将其放入 View 中。当我点击 main_im0 时,我预计触摸功能会达到 touchedview==focus 的条件。但是,我无法激活该条件?怎么了?

最佳答案

请启用

main_im0.userInteractionEnabled = YES;

对于UIImageView,默认是No

关于iOS 触摸 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11981863/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com