Avatar
transform を使ってアニメーションさせようとすると 開始位置がずれてしまうのですが、使い方おかしいところありますか?
4:17 AM
import UIKit import PlaygroundSupport class ViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) view.backgroundColor = .white print(view) let box = UIView() view.addSubview(box) box.bounds = CGRect(x: 0, y: 0, width: view.bounds.width - 40, height: view.bounds.width - 40) box.center = CGPoint(x: view.bounds.width / 2, y: view.bounds.width / 2 + 100) box.backgroundColor = .red box.transform = CGAffineTransform(scaleX: 0.8, y: 0.8) DispatchQueue.main.asyncAfter(deadline: .now() + 3) { UIView.animate( withDuration: 3, animations: { box.transform = CGAffineTransform.identity .translatedBy(x: 0, y: 200) }) } } } let vc = ViewController() vc.view.bounds = CGRect(x: 0, y: 0, width: 375, height: 667) PlaygroundPage.current.liveView = vc (edited)