gpt4 book ai didi

iphone - 创建类似于 UIAlertView 演示的 Pop 动画

转载 作者:行者123 更新时间:2023-12-03 18:17:56 26 4
gpt4 key购买 nike

我想以与 UIAlertView 相同的方式呈现一个 View - pop/spring。不幸的是,子类化 UIAlertView 并不是我需要呈现的 View 的一个选项。我已经编写了一些代码,但我似乎无法将其实现为我想要的那么现实。如果有任何类似的事情已经完成(我在谷歌上找不到任何东西),我将不胜感激任何有关更大现实主义的建议或链接。谢谢。

  - (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {

self.backgroundColor = [UIColor whiteColor];

v = [[UIView alloc] initWithFrame:CGRectMake(140, 140, 60, 60)];
v.backgroundColor = [UIColor blueColor];

[self addSubview:v];
[self animate];

}
return self;
}

- (void)animate {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(popStep1Complete)];
v.frame = CGRectMake(90, 90, 140, 140);
[UIView commitAnimations];
}

- (void)popStep1Complete {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.15];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(popStep2Complete)];
v.frame = CGRectMake(110, 110, 100, 100);
[UIView commitAnimations];
}

- (void)popStep2Complete {

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.15];
v.frame = CGRectMake(100, 100, 120, 120);
[UIView commitAnimations];
}

最佳答案

- (void) attachPopUpAnimation
{
CAKeyframeAnimation *animation = [CAKeyframeAnimation
animationWithKeyPath:@"transform"];

CATransform3D scale1 = CATransform3DMakeScale(0.5, 0.5, 1);
CATransform3D scale2 = CATransform3DMakeScale(1.2, 1.2, 1);
CATransform3D scale3 = CATransform3DMakeScale(0.9, 0.9, 1);
CATransform3D scale4 = CATransform3DMakeScale(1.0, 1.0, 1);

NSArray *frameValues = [NSArray arrayWithObjects:
[NSValue valueWithCATransform3D:scale1],
[NSValue valueWithCATransform3D:scale2],
[NSValue valueWithCATransform3D:scale3],
[NSValue valueWithCATransform3D:scale4],
nil];
[animation setValues:frameValues];

NSArray *frameTimes = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.9],
[NSNumber numberWithFloat:1.0],
nil];
[animation setKeyTimes:frameTimes];

animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.duration = .2;

[self.layer addAnimation:animation forKey:@"popup"];
}

关于iphone - 创建类似于 UIAlertView 演示的 Pop 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690775/

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