2016-04-12 1 views
0

私は何があって私iOSで活気あるテキストを動かすには?

(一種のログインビューのようにあなたは、多くのアプリケーションで参照してくださいね)、数秒間待機してトップにアニメーション化、視野の中心に挨拶アプリを作りたいんテキストをx軸の中央に置くことはできません。私のコードを調べて、間違いが何であるか教えてください。

あなたは

// Blur Effect 
    var blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light) 
    var blurEffectView = UIVisualEffectView(effect: blurEffect) 
    blurEffectView.frame = view.bounds 
    view.addSubview(blurEffectView) 

    // Vibrancy Effect 
    var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect) 
    var vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect) 
    vibrancyEffectView.frame = view.bounds 

    // Add label to the vibrancy view 

    vibrancyEffectView.contentView.addSubview(vibrantLabel) 

    vibrantLabel.textAlignment = NSTextAlignment.Center 


    // Add the vibrancy view to the blur view 
    blurEffectView.contentView.addSubview(vibrancyEffectView) 


    UIView.animateWithDuration(1, delay: 1, options: .CurveEaseIn, animations: {() -> Void in 

     self.vibrantLabel.frame = CGRectMake(0, 100, self.vibrantLabel.frame.width, self.vibrantLabel.frame.height) 
     }, completion: {(finished: Bool) -> Void in 
      self.view.alpha = 1 
    }) 
+0

代わりに、下にあるレイヤーを移動します。 self.vibrantLabel.layer.anchorPointを{0.5,0.5}に設定して、self..vibrantLabel.layer.position = {x、y} –

答えて

0

だけでアニメーション中に、ラベルのX原点を保つ、あなたの問題を解決するためにありがとうございました。 この行を試してください:

self.vibrantLabel.frame = CGRectMake(self.vibrantLabel.frame.origin.x, 100, self.vibrantLabel.frame.width, self.vibrantLabel.frame.height) 

あなたのラベルがその親ビューに左揃えアニメーション化されたので、あなたは、ゼロにx軸上の原点を設定しました。

+0

を移動してください。これは機能しませんでした。私は問題がvibrancyEffectViewであると思う。 vibrancyEffectViewにラベルをサブビューとして追加しない場合、ラベルの位置は正しいです。ただし、サブビューとして追加すると、デフォルトでラベルが画面の左側に表示されます。 –

0

解決策が見つかりました。 viewDidLayoutSubviews()で初期位置を設定し、次にviewDidAppear()でアニメーションを作成する必要がありました。

@IBOutlet var vibrantLabel: UILabel! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Blur Effect 

    var blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light) 
    var blurEffectView = UIVisualEffectView(effect: blurEffect) 
    blurEffectView.frame = view.bounds 
    view.addSubview(blurEffectView) 

    // self.vibrantLabel.layer.anchorPoint = (CGPointMake(-0.25, -2.65)) 

    // Vibrancy Effect 
    var vibrancyEffect = UIVibrancyEffect(forBlurEffect: blurEffect) 
    var vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect) 
    vibrancyEffectView.frame = view.bounds 

    // Add label to the vibrancy view 

    view.addSubview(vibrantLabel) 

    vibrantLabel.textAlignment = NSTextAlignment.Center 

    // Add the vibrancy view to the blur view 
    blurEffectView.contentView.addSubview(vibrancyEffectView) 

} 

override func viewDidLayoutSubviews() { 


    vibrantLabel.center = CGPointMake(view.frame.midX, view.frame.midY) 

} 

override func viewDidAppear(animated: Bool) { 

    UILabel.animateWithDuration(1.25, delay: 1, options: .CurveEaseInOut, animations: { 

     self.vibrantLabel.center = CGPointMake(self.view.frame.midX, 100) 

     }) { (Bool) in 

      print("success") 

    } 


} 
関連する問題