Cannot call value of non-function type 'CGFloat' with the alpha property

烂漫一生 提交于 2019-12-12 04:16:18

问题


I am debugging a dropdown menu I converted from Objective-C. In it, I have this function:

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()

    }

In there I have marked were the error is showing up, on the lines were self.container.alpha(containerAlpha) is. The error says Cannot call value of non-function type 'CGFloat', and this is the declaration for container:

@IBOutlet weak var container: UIImageView!

I have imported UIKit. What would be causing this error?

Let me now if you need more information.


回答1:


Since a UIImageView has an alpha property (not a method), you need to assign the alpha value to the UIImageView, like this:

 self.container.alpha = containerAlpha

On the other hand; if UIImageView did have an alpha method, you would use

self.container.alpha(containerAlpha)


来源:https://stackoverflow.com/questions/33945625/cannot-call-value-of-non-function-type-cgfloat-with-the-alpha-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!