如何在iOS中的动画图像上放置按钮?

如何在iOS中的动画图像上放置按钮?,ios,xcode,uiimageview,uibutton,Ios,Xcode,Uiimageview,Uibutton,在我的应用程序中,我有一组图像,它们每秒钟都在变动画。 我使用了以下代码 animateArrayImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"gallery-img-1.png"], [UIImage imageNamed:@"gallery-img-2.png"],nil]; animateImageView.animationImages =

在我的应用程序中,我有一组图像,它们每秒钟都在变动画。
我使用了以下代码

 animateArrayImages = [NSArray arrayWithObjects:
                   [UIImage imageNamed:@"gallery-img-1.png"],
                   [UIImage imageNamed:@"gallery-img-2.png"],nil];
animateImageView.animationImages = animateArrayImages;
animateImageView.animationDuration = 1.0f;
animateImageView.animationRepeatCount = 0;
[animateImageView startAnimating];
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(20, 20, 20, 20)];
[self.view addSubview:button];  
但是我得到了这样的输出
按钮将显示在图像的背景中。

但是我想在图像之前显示它

如果要将按钮置于图像顶部,可以在
addSubview之后调用以下方法:

[self.view bringSubviewToFront:button];

使用insertSubview:UpperSubView:或在addSubview:AnimateImageView之后调用addSubview:按钮您的触摸仍然可以正常工作。如果您在xib中有一个图像视图,那么可以手动添加按钮,也可以通过编程方式设置按钮的框架,类似于图像视图。