-1

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];
4

3 回答 3

1
UIButton*playButton = [UIButton buttonWithType:UIButtonTypeCustom];

试试这个..它会完美地工作..

[playButton setImage:[UIImage imageNamed:@"playIconPlay.png"] forState:UIControlStateNormal];

[playButton setFrame:CGRectMake(20,20,128,128)];

[playButton setTitle:@"Play Click" forState:UIControlStateNormal];

[playButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[playButton addTarget:self action:@selector(playButtonAction) forControlEvents:UIControlEventTouchUpInside];


[scrollView addSubview:playButton];
[scrollView bringSubviewToFront:playButton];
于 2013-10-30T04:31:11.797 回答
1

您可以在 UIView 中添加 UIImageView 和 UIButton,希望对您有所帮助。

UIView* view = [[UIView alloc] initWithFrame:CGRectMake(75, 10, 200, 150)];

UIImageView*myImageView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,150)];


myImageView.image=thumbnail;


[view addSubview:myImageView];

[scrollView addSubview:view];

UIButton*playButton=[[UIButton alloc] initWithFrame:CGRectMake(20,20,128,128)];

//[playButton setImage:[UIImage imageNamed:@"playIconPlay.png"] forState:UIControlStateNormal];

[playButton.buttonType:UIButtonTypeRoundedRect];

[playButton setTitle:@"Play Click" forState:UIControlStateNormal];

[playButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


[playButton addTarget:self action:@selector(playButtonAction) forControlEvents:UIControlEventTouchUpInside];


myImageView.userInteractionEnabled=YES;

[view addSubview:playButton];
于 2013-10-30T04:28:14.497 回答
0

在将 Button 添加为子视图之前,请将exclusiveTouch属性设置为YES.

playButton.exclusiveTouch = YES
[myImageView addSubview:playButton];

希望它会帮助你....享受编码..!!!

于 2013-10-30T04:33:48.410 回答