UIView changing its position in swift

前端 未结 4 2014
难免孤独
难免孤独 2021-01-31 10:21

How do I make a UIView slide up with a touch of a button from its original position and them bring it back down with a touch of a button? Using Swift and Xcode 6.

4条回答
  •  不知归路
    2021-01-31 10:39

    Hi create this extends if you want. For Swift

    Create File Extends.Swift and add this code

    /**
        Extension UIView
        by DaRk-_-D0G
    */
    extension UIView {
        /**
        Set x Position
    
        :param: x CGFloat
        by DaRk-_-D0G
        */
        func setX(#x:CGFloat) {
            var frame:CGRect = self.frame
            frame.origin.x = x
            self.frame = frame
        }
        /**
        Set y Position
    
        :param: y CGFloat
        by DaRk-_-D0G
        */
        func setY(#y:CGFloat) {
            var frame:CGRect = self.frame
            frame.origin.y = y
            self.frame = frame
        }
        /**
        Set Width
    
        :param: width CGFloat
        by DaRk-_-D0G
        */
        func setWidth(#width:CGFloat) {
            var frame:CGRect = self.frame
            frame.size.width = width
            self.frame = frame
        }
        /**
        Set Height
    
        :param: height CGFloat
        by DaRk-_-D0G
        */
        func setHeight(#height:CGFloat) {
            var frame:CGRect = self.frame
            frame.size.height = height
            self.frame = frame
        }
    }
    

    For Use (inherits Of UIView)

    inheritsOfUIView.setX(x: 100)
    button.setX(x: 100)
    view.setY(y: 100)
    

提交回复
热议问题