码迷,mamicode.com
首页 > 其他好文 > 详细

UIView--震动效果

时间:2014-11-27 21:54:26      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:io   os   for   on   ad   ef   as   line   size   

//震动效果
- (void)shake:(UIView *)view
{
CGRect frame = view.frame;
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

CGMutablePathRef shakePath = CGPathCreateMutable();
CGPathMoveToPoint(shakePath, NULL, frame.origin.x+frame.size.width/2, frame.origin.y+frame.size.height/2);
int index;
for (index = 3; index >=0; --index)
{
CGPathAddLineToPoint(shakePath, NULL, frame.origin.x+frame.size.width/2 - frame.size.width * 0.02f * index, frame.origin.y+frame.size.height/2);
CGPathAddLineToPoint(shakePath, NULL, frame.origin.x+frame.size.width/2 + frame.size.width * 0.02f * index, frame.origin.y+frame.size.height/2);
}
CGPathCloseSubpath(shakePath);

shakeAnimation.path = shakePath;
shakeAnimation.duration = 0.5f;
shakeAnimation.removedOnCompletion = YES;

[view.layer addAnimation:shakeAnimation forKey:nil];
CFRelease(shakePath);
}

UIView--震动效果

标签:io   os   for   on   ad   ef   as   line   size   

原文地址:http://www.cnblogs.com/zhangliukou/p/4127100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!