0

ボタンの touchUpInside では、一連のコードが実行され (すべてのデータに関連し、メイン関数のコードはビュー オブジェクトを変更しません)、コードが最後に行うことは、下に貼り付けたアニメーション関数を呼び出すことです。問題は、アニメーションが本来のように見えないことです。

希望のアニメーション:

  1. footerImg はフェードアウトする必要があります
  2. フッターバーのテキストはフェードインする必要があります
  3. フッターバーのテキストはフェードアウトする必要があります
  4. footerImg がフェードインするはずです

テキストと画像は画面上で同じ位置を占めるため、ビジュアルは一方を他方に置き換えてから元の状態に戻す必要があります。ビューは互いにネストされておらず、同じコンテナーを共有しています。

シミュレーターで見た実際のアニメーション:

-footerImg は表示されません -footerBar テキストはトリガーがタップされた直後に表示され、アニメーションはありません -footerBar テキストはフェードアウトします -footerImg はフェードインします

footerBar は UIButton です

-アクションが開始される前の開始状態は、ボタンが空でクリアであることです (ユーザーには見えません)。

-重要な場合、これは機能をトリガーしたボタンではありません

-背景が明確であるため、そのテキストのみがアニメーション化されている必要があります

footerImg は UIImageView です

-アイコン画像だけで、特別なことは何もありません

func animateFeedback() {
    UIView.animateWithDuration(0.25, delay: 0.0, usingSpringWithDamping: 1.0, initialSpringVelocity: 0, options: nil, animations: {
            self.footerImg.alpha = 0
            self.footerBar.alpha = 0

    },
        completion: { finished in
            self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
        }
    )

    UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
            self.footerBar.alpha = 1
        }
        , completion: nil
    )
    UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
            self.footerBar.alpha = 0
        }
        , completion: { finished in
            self.footerBar.setTitle("", forState: UIControlState.Normal)
        }
    )
    UIView.animateWithDuration(0.25, delay: 1.5, options: nil, animations: {
            self.footerImg.alpha = 1
        }
        , completion: nil
    )
}
4

2 に答える 2

1

シーケンス アニメーションの場合は、完了ブロックにアニメーションを配置する必要があります。例えば

フッターバーのテキストはフェードインする必要があります

フッターバーのテキストはフェードアウトする必要があります

これを試して:

        self.footerBar.alpha = 0;

        UIView.animateWithDuration(1.5, delay: 0.5, options: nil, animations: {
            self.footerBar.alpha = 1
        }
        , completion: { finished in
            UIView.animateWithDuration(0.75, delay: 1.25, options: nil, animations: {
               self.footerBar.alpha = 0
            }
            , completion: { finished in
               self.footerBar.setTitle("", forState: UIControlState.Normal)
            }
            )
       }
       )

そして他の人も同じ

于 2015-08-20T10:10:17.123 に答える
0

「animateFeedback()」にあるすべてのコードにコメントを付けて、以下のコードを貼り付けます

UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
        self.footerImg.alpha = 0;
        self.footerBar.setTitle("Item added", forState: UIControlState.Normal)
        },
        completion: { finished in
            UIView.animateWithDuration(1.5, delay: 0, options: nil, animations: { () -> Void in
                self.footerImg.alpha = 1;
                self.footerBar.setTitle("", forState: UIControlState.Normal)
                },
                completion: { finished in
                }
            )
        }
    )
于 2015-08-20T11:45:09.537 に答える