-(voID)errorShake{ [UIVIEw beginAnimations:nil context:NulL]; [UIVIEw setAnimationDuration:1.0]; [lockImage settransform:CGAffinetransformMakeRotation(-5 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-10 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-15 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-20 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-15 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-10 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(-5 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(0 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(5 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(10 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(15 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(20 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(15 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(10 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(5 * M_PI / 180.0)]; [lockImage settransform:CGAffinetransformMakeRotation(0 * M_PI / 180.0)]; [UIVIEw commitAnimations];}
请你告诉我,我怎么能让我的图像震动?
解决方法 这是我用于这个效果的代码。-(voID)shakeVIEw { CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"]; [shake setDuration:0.1]; [shake setRepeatCount:2]; [shake setautoreverses:YES]; [shake setFromValue:[NSValue valueWithCGPoint: CGPointMake(lockImage.center.x - 5,lockImage.center.y)]]; [shake setTovalue:[NSValue valueWithCGPoint: CGPointMake(lockImage.center.x + 5,lockImage.center.y)]]; [lockImage.layer addAnimation:shake forKey:@"position"]; }
正如Jere所说。确保包含导入:
#import <QuartzCore/QuartzCore.h>
您也可以将其添加为UIVIEw中的类别。
总结以上是内存溢出为你收集整理的iphone – 如何使“摇动”动画全部内容,希望文章能够帮你解决iphone – 如何使“摇动”动画所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)