@interface TimingCurveViewController : UIViewController {
IBOutlet UIImageView *basketBall;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[UIView beginAnimations:@"movement" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; //<label id="code.timingcurve.easeIn"/>
[UIView setAnimationDuration:1.0f];
[UIView setAnimationRepeatCount:3];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint center = basketBall.center;
if(center.y > 85.0f) {
center.y -= 295.0f;
basketBall.center = center;
} else {
center.y += 295.0f;
basketBall.center = center;
}
[UIView commitAnimations];
}
- (void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor = [self colorWithRGBHexString:@"#abcdef"];
}
- (UIColor *)colorWithRGBHexString:(NSString *)rgbColor{
NSString *cString = rgbColor;
//去除空格并大写NSCharacterSetwhitespaceAndNewlineCharacterSet
cString = [[cString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
if ([cString length] < 6) {
//返回默认颜色
return [UIColor redColor];
}
if ([cString hasPrefix:@"0x"]) {
cString = [cString substringFromIndex:2];
}else if ([cString hasPrefix:@"#"]){
cString = [cString substringFromIndex:1];
}
if ([cString length] != 6) {
//返回默认颜色
return [UIColor redColor];
}
NSRange range;
range.length = 2;
range.location = 0;
NSString *rString = [cString substringWithRange:range];
range.location = 2;
NSString *gString = [cString substringWithRange:range];
range.location = 4;
NSString *bString = [cString substringWithRange:range];
unsigned int r,g,b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:(float)r/255.0 green:(float)g/255.0 blue:(float)b/255.0 alpha:1.0f];
}