【问题标题】:How to make UIView not appear on background but still appear over a UIImageView (subview)如何使 UIView 不出现在背景上但仍出现在 UIImageView (子视图)上
【发布时间】:2014-08-24 03:08:19
【问题描述】:

我有一个 UIImageView。我也有看法。我希望视图显示在 UIImageView 的顶部,因为它在屏幕上显示动画。我不希望视图出现在背景中。

我该怎么做?

我尝试通过添加另一个子视图来更改子视图的顺序,但是这是不可能的。

我正在考虑使用图层而不是视图来制作动画,但是 UIImageView 周围有透明部分。

代码:(注意:isAnimating是类属性,不用管它)

@IBAction func AnimateBtnTapped(sender: AnyObject) {
    if (isAnimating == false) {

        isAnimating = true

        UIView.animateWithDuration(0.6, delay: 0.0, options: .Repeat, animations: {
            self.glintImageConstraint.constant += 450
            self.view.layoutIfNeeded()
            }, completion: nil)


    } else {

        isAnimating = false

        self.glintImageView.layer.removeAllAnimations() //stop animation
        self.glintImageConstraint.constant = -200 //set glintImage to original position
        self.view.layoutIfNeeded()

    }
}

我的 UIImageView 是一个奖章。 glintImageView 是它上面的对象动画。

编辑:我要求与 Shimmer (https://github.com/facebook/Shimmer) 等效,但是对于 UIImageView。

【问题讨论】:

  • 添加您的代码。你做了什么?
  • 对不起。添加它。 ImageView 和 view 分别通过 storyboard/autolayout 添加。
  • 我正在尝试模拟此视频中显示的效果:youtube.com/watch?v=_U23xAUY6N4
  • 如果您只是需要将子视图放在前面,您可以使用bringSubviewToFront。
  • 不..这绝对不是我想要做的..

标签: ios objective-c iphone swift


【解决方案1】:

我认为你必须使用核心动画。如果您对图像视图使用CALayer 并为其添加了遮罩层,然后为要显示在图像顶部的视图使用子层,它可能会起作用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多