【发布时间】:2013-10-30 04:19:15
【问题描述】:
我有imageview,我在其中添加UIButton,当我单击按钮时它会显示按钮,它不会调用按钮的操作。这是我正在使用的代码,我还设置了imageView.userInteraction=enabled,但它仍然没有调用操作。
UIImageView*myImageView=[[UIImageView alloc] initWithFrame:CGRectMake(75,10,200,150)];
myImageView.image=thumbnail;
myImageView.userInteractionEnabled=YES;
[scrollView addSubview:myImageView];
UIButton*playButton=[[UIButton alloc] initWithFrame:CGRectMake(20,20,128,128)];
//[playButton setImage:[UIImage imageNamed:@"playIconPlay.png"] forState:UIControlStateNormal];
[playButton.buttonType:UIButtonTypeRoundedRect];
scrollView.userInteractionEnabled=YES;
myImageView.userInteractionEnabled=YES;
[playButton setTitle:@"Play Click" forState:UIControlStateNormal];
[playButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[playButton addTarget:self action:@selector(playButtonAction) forControlEvents:UIControlEventTouchUpInside];
myImageView.userInteractionEnabled=YES;
[myImageView addSubview:playButton];
【问题讨论】:
-
添加这一行 [myImageView bringSubviewToFront: playButton];然后尝试..
-
这个也不行
-
imageView 我用作背景很大,这就是我使用按钮的原因
-
@QueenSolutions:用buttontype初始化按钮,然后设置frame。无需为 imageView 设置 userInteractionEnabled。
-
如果你的imageview不在前面,那么如何将触摸事件传递给它?将您的图像视图放在前面或至少将播放按钮放在前面
标签: ios uiimageview uibutton