如何实现视图从左到右的动画过渡(类似于推送视图)。当我点击按钮时,视图应该从左侧向右侧过渡。请指导我并提供一些示例链接。
谢谢。
谢谢。
// Set up view2
view2.frame = view1.frame;
view2.center = CGPointMake(view1.center.x + CGRectGetWidth(view1.frame), view1.center.y);
[view1.superview addSubview: view2];
// Animate the push
[UIView beginAnimations: nil context: NULL];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)];
view2.center = view1.center;
view1.center = CGPointMake(view1.center.x - CGRectGetWidth(view1.frame), view1.center.y);
[UIView commitAnimations];
接着(可选),实现此方法以将view1从视图层次结构中移除:
- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context {
[view1 removeFromSuperview];
}
CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:transition forKey:nil];
[self presentViewController:YOUR_VIEWCONTROLLER animated:YES completion:nil];
CGRect viewLeftRect;//final frames for left view
CGRect viewRightRect;//final frames for right view
[UIView animateWithDuration:0.3f animations:^{
[viewLeft setFrame:viewLeftRect];
[viewRight setFrame:viewRightRect];
} completion:^(BOOL finished) {
//do what ever after completing animation
}];
您也可以像这样从右到左添加动画:
scrAnimation.frame=CGRectMake(248, 175, 500, 414); //your view start position
[UIView animateWithDuration:0.5f
delay:0.0f
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
[scrAnimation setFrame:CGRectMake(0, 175, 500, 414)]; // last position
}
completion:nil];