iOS常用功能和UI效果的实现技术

ios UIView常用动画效果

2016-03-08  本文已影响1212人  代码干货

由小变大
<pre>- (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait
{
__block BOOL done = wait;
view.transform = CGAffineTransformMakeScale(0, 0);
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformIdentity;

} completion:^(BOOL finished) {
    done = NO;
}];
while (done == YES)
    [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];

}</pre>

//大变小 函数
<pre>- (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
__block BOOL done = wait;
view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformMakeScale(0, 0);
} completion:^(BOOL finished) {
done = YES;
}];
while (done == NO)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}</pre>

二,如果需要类似UIAlertView那种动画
小变大动画
<pre>- (void)zoomIn: (UIView *)view andAnimationDuration: (float) duration
{
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = duration;
//animation.delegate = self;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
[view.layer addAnimation:animation forKey:nil];
}</pre>
原文链接
ios UIView常用动画效果
大变小
<pre>- (void)zoomOut: (UIView *)view andAnimationDuration: (float) duration andWait:(BOOL) wait{
__block BOOL done = wait;
view.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:duration animations:^{
view.transform = CGAffineTransformMakeScale(0, 0);
view.alpha = 0.0;
} completion:^(BOOL finished) {
done = YES;
}];
while (done == NO)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
}</pre>

Creating a Pop animation similar to the presentation of UIAlertView
<pre>- (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"];
}</pre>

上一篇下一篇

猜你喜欢

热点阅读