不能使用alpha属性

时间:2015-11-26 19:14:31

标签: swift uikit swift2 uiviewanimation cgfloat

我正在调试从Objective-C转换的下拉菜单。在其中,我有这个功能:

func showMenu() {
        self.menu.hidden = false
        self.menu.translatesAutoresizingMaskIntoConstraints = true

        closedMenuShape.removeFromSuperlayer()

        if shouldDisplayDropShape {
            self.view.layer.addSublayer(openMenuShape)
        }

        // Set new origin of menu
        var menuFrame: CGRect = self.menu.frame
        menuFrame.origin.y = self.menubar.frame.size.height - self.offset()


        var containerAlpha: CGFloat = fadeAlpha

        if SYSTEM_VERSION_LESS_THAN("7.0") {
            UIView.beginAnimations(nil, context: nil)
            UIView.setAnimationCurve(.EaseInOut)
            self.menu.frame = menuFrame
            self.container.alpha(containerAlpha) <======= Error
        }
        else {
            UIView.animateWithDuration(0.4,
                                delay: 0.0,
               usingSpringWithDamping: 1.0,
                initialSpringVelocity: 4.0,
                              options: .CurveEaseInOut,
                           animations: {
                                self.menu.frame = menuFrame
                                self.container.alpha(containerAlpha) <==== Error

                }, completion: {(finished: Bool) in
             })
           }

        UIView.commitAnimations()

    }

在那里,我标记了错误显示,行self.container.alpha(containerAlpha)是。错误显示Cannot call value of non-function type 'CGFloat',这是容器的声明:

@IBOutlet weak var container: UIImageView!

我已导入UIKit。会导致此错误的原因是什么?

如果您需要更多信息,请立即告诉我。

1 个答案:

答案 0 :(得分:1)

由于UIImageView具有alpha属性(不是方法),因此您需要将alpha值分配给UIImageView,如下所示:

 self.container.alpha = containerAlpha

另一方面;如果UIImageView 方法,您可以使用

self.container.alpha(containerAlpha)