【问题标题】:How to place a button on animation image in iOS?如何在iOS中的动画图像上放置一个按钮?
【发布时间】:2014-01-01 00:36:35
【问题描述】:

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

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

但是我得到这样的输出
该按钮将显示在图像的背景中。
但我想在图像之前显示它

【问题讨论】:

  • 使用 insertSubview:aboveSubview: 或在 addSubview:animateImageView 之后调用 addSubview:button
  • 您的触摸仍然可以正常工作。看看你是否在 xib 中有一个图像视图,然后手动添加按钮,也可以通过编程设置按钮的框架类似于图像视图。

标签: ios xcode uiimageview uibutton


【解决方案1】:

如果你想把按钮放在图片上方,可以在addSubview:之后调用下面的方法

[self.view bringSubviewToFront:button];

【讨论】:

    猜你喜欢
    • 2012-02-25
    • 2016-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-09
    • 2018-12-23
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多