Iphone 旋转设备时反转的页面卷曲
我有一个非常小的视图,我正在用这样的页面卷曲设置动画:Iphone 旋转设备时反转的页面卷曲,iphone,ios,ipad,Iphone,Ios,Ipad,我有一个非常小的视图,我正在用这样的页面卷曲设置动画: [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO]; 它工作得很好,视图从右侧向上卷曲,但如果我将设备旋转180度,则会从左侧发生卷曲 我的应用程序支持两种横向方向。不允许有肖像 如何解决这个问题?首先 您是否尝试过使用: [UIView setAnimationBeginsFromCurrentState:N
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:NO];
它工作得很好,视图从右侧向上卷曲,但如果我将设备旋转180度,则会从左侧发生卷曲
我的应用程序支持两种横向方向。不允许有肖像
如何解决这个问题?首先
您是否尝试过使用:
[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];
请检查此处的答案:抱歉,这不是此答案的解决方案。很明显,这个问题与设备旋转有关,但是我该如何解决呢?你支持纵向和横向吗?你可以参考更多关于方向的细节。是的!!!!问题解决了。你能解释一下原因吗?如果此包装器位于viewcontroller的子视图中,为什么它不会遇到相同的问题?所描述的行为可能是由错误引起的。