我正在尝试使用 Swift 增加 NSWindow 的大小。(苹果电脑)
现在,我可以在没有动画的情况下做到这一点,但我不确定如何使用动画来做到这一点。
A. 我会对代码感兴趣。
B. 如果有教程或书籍,是否可以删除链接。
以下代码是从另一个 SO 答案中提取的,但是是否可以延迟该CAKeyframeAnimation动画的开始,类似于 UIViewanimateWithDuration提供delay属性的方式?
根据类文档,该类CAKeyframeAnimation似乎不包含延迟属性。
let animation = CAKeyframeAnimation(keyPath: "transform.translation.x")
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
animation.duration = 1.0
animation.repeatCount = 2
animation.values = [-10, 10, -10, 10, -5, 5, -2, 2, 0]
view.layer.addAnimation(animation, forKey: "shake")
Run Code Online (Sandbox Code Playgroud) core-animation uiview cakeyframeanimation uiviewanimation ios
尝试了几种方法让它的气泡效果从下到上移动。
我能够将其从底部移动到顶部。但我无法做出像气泡一样的效果。
@State private var bouncing = true
var body: some View {
Image("bubble").resizable()
.aspectRatio(contentMode: .fit)
.frame(height: 40)
.frame(maxHeight: .infinity, alignment: bouncing ? .bottom : .top)
.animation(Animation.easeInOut(duration: 5.0).repeatForever(autoreverses: false))
.onAppear {
self.bouncing.toggle()
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以在iOS中进行某种摇摆动画.例如,摇摆动画就像一个在风中飘扬的商店标志.想想西部片.按下按钮时我想做这种动画.我想要一种西方式的感觉,这真的会让它超越顶级.如果您知道如何做这样的事情,请提前感谢.
我对Objective-C的经验不多.我试图在用户按下按钮后结束动画.在viewDidLoad我添加了这个:
UILongPressGestureRecognizer *recoginzer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onPress:)];
[_buttonStart addGestureRecognizer:recoginzer];
Run Code Online (Sandbox Code Playgroud)
然后在我用来setCompletionBlock确定动画何时结束的方法中,但它不起作用.
-(void)onPress:(UILongPressGestureRecognizer*)longpress {
if (longpress.state == UIGestureRecognizerStateBegan) {
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(2, 2, _buttonStart.frame.size.width-4, _buttonStart.frame.size.height-4) cornerRadius:(_buttonStart.frame.size.width/2)-8].CGPath;
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor whiteColor].CGColor;
circle.lineWidth = 2.5;
[_buttonStart.layer addSublayer:circle];
[CATransaction begin];
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 3.0;
drawAnimation.repeatCount = 1.0;
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[circle addAnimation:drawAnimation forKey:@"drawCircleAnimation"];
[CATransaction setCompletionBlock:^{
NSLog(@"DONE");
}];
[CATransaction commit];
} else if …Run Code Online (Sandbox Code Playgroud)