gpt4 book ai didi

ios - 如何快速移动图像

转载 作者:可可西里 更新时间:2023-11-01 00:58:30 25 4
gpt4 key购买 nike

任何人都可以向我解释如何创建圆形路径并围绕它移动图像。

我需要的: enter image description here

let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100,y: 100), radius:  CGFloat(20), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

我发现了圆的路径是怎么做的,但其余的我不知道该怎么做。我是 iOS 开发的新手。

而且,我需要在打开页面时开始执行此操作。

最佳答案

检查这段代码,objectToMove 是一个来自 storyBoard 的 UIView 来测试,这里我使用你的路径代码但是我添加了更多的半径

import UIKit

class ViewController: UIViewController {
@IBOutlet weak var objectToMove: UIView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

let orbit = CAKeyframeAnimation(keyPath: "position")
var affineTransform = CGAffineTransformMakeRotation(0.0)
affineTransform = CGAffineTransformRotate(affineTransform, CGFloat(M_PI))
let circlePath = UIBezierPath(arcCenter: CGPoint(x: 100 - (100/2),y: 100 - (100/2)), radius: CGFloat(100), startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)
orbit.path = circlePath.CGPath
orbit.duration = 4
orbit.additive = true
orbit.repeatCount = 100
orbit.calculationMode = kCAAnimationPaced
orbit.rotationMode = kCAAnimationRotateAuto

objectToMove.layer .addAnimation(orbit, forKey: "orbit")
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


}

希望对你有帮助,谢谢

关于ios - 如何快速移动图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39275901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com