下面是實現的代碼git
//選擇動畫github
- (IBAction)selectAnimationTypeButton:(id)sender {動畫
UIButton *button = sender;url
animationType animationType = button.tag;orm
NSString *subtypeString;對象
switch (_subType) {ip
case 0:animation
subtypeString = kCATransitionFromLeft;string
break;it
case 1:
subtypeString = kCATransitionFromBottom;
break;
case 2:
subtypeString = kCATransitionFromRight;
break;
case 3:
subtypeString = kCATransitionFromTop;
break;
default:
break;
}
_subType += 1;
if (_subType > 3) {
_subType = 0;
}
switch (animationType) {
case Fade:
[self transitionWithType:kCATransitionFade withSubtype:subtypeString forView:self.view];
break;
case Push:
[self transitionWithType:kCATransitionPush withSubtype:subtypeString forView:self.view];
break;
case Reveal:
[self transitionWithType:kCATransitionReveal withSubtype:subtypeString forView:self.view];
break;
case MoveIn:
[self transitionWithType:kCATransitionMoveIn withSubtype:subtypeString forView:self.view];
break;
case Cube:
[self transitionWithType:@"cube" withSubtype:subtypeString forView:self.view];
break;
case SuckEffect:
[self transitionWithType:@"suckEffect" withSubtype:subtypeString forView:self.view];
break;
case OgleFlip:
[self transitionWithType:@"oglFlip" withSubtype:subtypeString forView:self.view];
break;
case RippleEffect:
[self transitionWithType:@"rippleEffect" withSubtype:subtypeString forView:self.view];
break;
case PageCurl:
[self transitionWithType:@"pageCurl" withSubtype:subtypeString forView:self.view];
break;
case pageUnCurl:
[self transitionWithType:@"pageUnCurl" withSubtype:subtypeString forView:self.view];
break;
case CameraIrisHollowOpen:
[self transitionWithType:@"cameraIrisHollowOpen" withSubtype:subtypeString forView:self.view];
break;
case CameraIrisHollowClose:
[self transitionWithType:@"cameraIrisHollowClose" withSubtype:subtypeString forView:self.view];
break;
case CurlDow:
[self animationWithView:self.view withAnimationTransition:UIViewAnimationTransitionCurlDown];
break;
case CurlUp:
[self animationWithView:self.view withAnimationTransition:UIViewAnimationTransitionCurlUp];
break;
case FlipFromLeft:
[self animationWithView:self.view withAnimationTransition:(UIViewAnimationTransitionFlipFromLeft)];
break;
case FlipFromRight:
[self animationWithView:self.view withAnimationTransition:(UIViewAnimationTransitionFlipFromRight)];
break;
default:
break;
}
static int i = 1;
if (i > 6) {
i = 1;
}
[self addBackgroundImgWithName:[NSString stringWithFormat:@"0%d.jpg",i]];
i += 1;
}
#pragma CATransition========動畫實現=======
- (void)transitionWithType:(NSString*) type withSubtype:(NSString*)subType forView:(UIView*)view{
//建立CATranstion對象
CATransition *animation = [CATransition animation];
//設置運動時間
animation.duration = DURATION;
//設置動畫的類型type
animation.type = type;
if (subType != nil) {
//設置子類
animation.subtype = subType;
}
//設置動畫出現的時候的運動速度
animation.timingFunction = UIViewAnimationOptionCurveEaseInOut;
[view.layer addAnimation:animation forKey:@"animation"];
}
#pragma mark ============UIView動畫實現=============
- (void)animationWithView:(UIView*)view withAnimationTransition:(UIViewAnimationTransition)transtion{
[UIView animateWithDuration:DURATION animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:transtion forView:view cache:YES];
}];
}
- (void)addBackgroundImgWithName:(NSString*)imgeName{
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:imgeName]];
}
代碼放到github上,喜歡就給個Star:https://github.com/JakeTorres/Jake-sHouse