我有一个很小的观点,我正在使用像这样的页面卷曲来动画:
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
效果很好,视图从右侧向上卷曲,但如果我将设备旋转180度,则卷曲从左侧发生。
我的应用程序支持两种横向方向。没有肖像允许。
如何解决?
答案 0 :(得分:1)
首先 你尝试过使用过:
[UIView setAnimationBeginsFromCurrentState:NO];
这是你的问题:
当您在横向模式中“蜷缩”时,使用右侧的按钮,页面开始从右上角向左下方翻转(意味着,您用右手翻动页面,然后朝向书的左侧。也意味着书的装订在左边。)
当你做同样的事情时,但是左边的按钮,即使正确旋转内容,动画也不会旋转,在vc中说“shouldAutorotateToInterfaceOrientation:True”。结果,动画从左下角到右上角,给人的印象是书的装订现在在右边。
一些代码来说明:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
view1 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[view1 setBackgroundColor:[UIColor greenColor]];
[view1 setFont:[UIFont systemFontOfSize:80]];
[view1 setText:@"VIEW 1"];
view2 = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[view2 setBackgroundColor:[UIColor redColor]];
[view2 setFont:[UIFont systemFontOfSize:80]];
[view2 setText:@"VIEW 2"];
}
return self;
}
-(void)didSwipeNext
{
[self performSelector:@selector(swipePrevious) withObject:nil afterDelay:1];
}
-(void)didSwipePrevious
{
[self performSelector:@selector(swipeNext) withObject:nil afterDelay:1];
}
-(void)swipeNext
{
[UIView beginAnimations:@"curl" context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDidStopSelector:@selector(didSwipeNext)];
[view1 removeFromSuperview];
[self.view addSubview:view2];
[UIView commitAnimations];
}
-(void)swipePrevious
{
[UIView beginAnimations:@"curl" context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDidStopSelector:@selector(didSwipePrevious)];
[view2 removeFromSuperview];
[self.view addSubview:view1];
[UIView commitAnimations];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:view1];
[self performSelector:@selector(swipeNext) withObject:nil afterDelay:1];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
循环是为要刷新的页面中的所有UI元素创建一个包装器(UIView)。我让包装器成为视图控制器视图和包装器的所有其他视图子视图的唯一子视图。并将目标修改为包装,如下所示
[UIView transitionWithView:self.wrapperView
duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{[imageView setImage:foregroundImage];}
completion:nil];