I 4つのボタンがあり、すべてがUIViewとUIImageViewのアニメーションが異なるのはなぜですか?
- 同じアニメーションfuncを使用しimageViewWithoutDelay
- imageViewWithDelay
- ViewWithoutDelay
- ViewWithDelay
私のコード:
import UIKit
class ViewController: UIViewController {
@IBAction func imageViewithoutDelay(_ sender: AnyObject) {
let circleImage = UIImageView()
// kindly add your own image.
circleImage.image = UIImage(named: "empty")
animate(inputView: circleImage, delay: false)
}
@IBAction func imageViewWithDelay(_ sender: UIButton) {
let circleImage = UIImageView()
circleImage.image = UIImage(named: "empty")
animate(inputView: circleImage, delay: true)
}
func animate(inputView : UIView, delay: Bool){
inputView.layer.cornerRadius = inputView.frame.size.width/2
inputView.clipsToBounds = true
inputView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(inputView)
let screenSize = UIScreen.main.bounds
let screenHeight = screenSize.height * 0.10
inputView.center.y = screenHeight
view.setNeedsLayout()
view.setNeedsDisplay()
if delay == true{
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1), execute: {
UIView.animate(withDuration: 2.5, animations: {
inputView.alpha = 0.0
let screenSize = UIScreen.main.bounds
let screenHeight = screenSize.height * 0.10
inputView.center.y -= screenHeight
})
})} else{
UIView.animate(withDuration: 2.5, animations: {
inputView.alpha = 0.0
let screenSize = UIScreen.main.bounds
let screenHeight = screenSize.height * 0.10
inputView.center.y -= screenHeight
})
}
}
override func viewDidLoad() {
super.viewDidLoad()
}
}
私を楽しませるのは、UIview
& UIImageView
の異なる動作です。
UIImageView
インスタンスが唯一の意図したとおり、私は遅れを使用場合(原点からアップ行く)アニメーション化します。ただし、遅延ブロックを使用しない場合は、UIImageViewインスタンスが最初に降下し、を起点にしてアニメーション化します()。
UIView
は、異なる動作を示していません。その起源から生き生きとして上がる。
この質問は、thisオリジナルの質問に接しています。
です。 1.アニメーションラインに到達するまでには、すでにインターフェイスに入っていませんか? 2.なぜこのように起こるのですか?なぜそれは変わるの?それがなぜ起こり得ないのか、それがなぜimageViewのためにできるのかという理由はありません。 – Honey
私はそれがnon-imageviewのために働く理由を知らない。 - ランロップがサイクルする機会があるまでは、「インターフェース内」ではありません。あなたが次のrunloopのメインスレッドに戻ってくるので、ゼロの遅延でさえ十分であるはずです。あなたのイメージビューでそれを試してみてください。 – matt
'.seconds(0)'への変更を意味しますか?私はそれをして、今私の両方のimageViewsは、原点にアニメーションをドロップダウンします。私も '.nanoseconds(1)'を試しましたが、やはり同じ誤った結果を得ました。 – Honey