【问题标题】:Swift: Load .Xib with animationSwift:加载带有动画的 .Xib
【发布时间】:2015-10-29 20:06:34
【问题描述】:

目前我正在加载一个新的 .Xib 类 CreateAnAccount: UIView form a button press on another view。

目前它会立即切换到 Xib,这很棒,但是有没有办法对此进行动画处理?下面是按钮中的代码。

    @IBAction func createAnAccount(sender: AnyObject) {
    let createAnAccountView = NSBundle.mainBundle().loadNibNamed("CreateAnAccount", owner: self, options: nil)[0] as! CreateAnAccount
    createAnAccountView.frame = CGRectMake(0, 0, UIScreen.mainScreen().applicationFrame.size.width, UIScreen.mainScreen().applicationFrame.size.height + 20)
    createAnAccountView.loginHandler = loginHandler
    self.addSubview(createAnAccountView)
    println("Create An Account Pressed")
}

【问题讨论】:

标签: ios swift animation xib


【解决方案1】:

斯威夫特 4。只需将您的动画代码放入layoutSubviews func。非常适合我。

override func layoutSubviews() {
    super.layoutSubviews()
    animate()
}

func animate() {
    self.transform = CGAffineTransform(scaleX: 0.3, y: 2)
    UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0, options: [.allowUserInteraction, .curveEaseOut], animations: {
        self.transform = .identity
    })
    self.alpha = 1
}

【讨论】:

    【解决方案2】:

    斯威夫特 5。 @coldembrace 答案

    func animate() {
            self.view.transform = CGAffineTransform(scaleX: 0.3, y: 2)
            UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.3, initialSpringVelocity: 0, options: [.allowUserInteraction, .curveEaseOut], animations: {
                self.view.transform = .identity
            })
            self.view.alpha = 1
        }
    

    【讨论】:

      【解决方案3】:

      你可以这样试试

      UIView.transitionWithView(self.view, duration: 0.5, options:UIViewAnimationOptions.CurveEaseInOut,animations: {self.view.addSubview(createAnAccountView)}, completion: nil)  
      

      此外,您更改 UIViewAnimationOptions 以获得所需的效果。

      【讨论】:

      • 这似乎仍然不起作用,视图确实发生了变化,但没有动画。你确定这可以在 .Xib 上使用吗?
      猜你喜欢
      • 1970-01-01
      • 2019-04-19
      • 2018-01-13
      • 2015-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多