iPhone向左卷曲和向右卷曲过渡
我正在寻找一种在iPhone上执行iPhone向左卷曲和向右卷曲过渡,iphone,curl,uiview,transition,cgaffinetransform,Iphone,Curl,Uiview,Transition,Cgaffinetransform,我正在寻找一种在iPhone上执行UIViewAnimationTransitionUrlUp或UIViewAnimationTransitionUrlDown转换的方法,但不是从上到下,而是从左到右(或在横向模式下为上/下)执行转换。我在网上看到过几次这样的问题,但没有一个SEM能得到答案。然而,我觉得这是可行的 我尝试过更改视图的变换和View.layer的变换,但这并不影响变换。由于当设备改变方向时,转换会发生变化,我认为有一种方法可以愚弄设备在纵向模式下使用横向转换,反之亦然?我认为除了
UIViewAnimationTransitionUrlUp
或UIViewAnimationTransitionUrlDown
转换的方法,但不是从上到下,而是从左到右(或在横向模式下为上/下)执行转换。我在网上看到过几次这样的问题,但没有一个SEM能得到答案。然而,我觉得这是可行的
我尝试过更改视图的变换和View.layer的变换,但这并不影响变换。由于当设备改变方向时,转换会发生变化,我认为有一种方法可以愚弄设备在纵向模式下使用横向转换,反之亦然?我认为除了编写自定义动画之外没有其他方法 更重要的是,你可能不应该尝试这样做。“向上卷曲”和“向下卷曲”是用户界面语法的一部分,它告诉用户在现有视图上正在提升或放下视图。它应该像一张便条,被放下,然后取下。左右卷曲最有可能被解释为类似于从书中撕下一页的东西。这会让用户感到困惑 每当您发现自己试图在接口中做一些标准API不容易做到的事情时,您应该问问自己,这样一种新方法是否会向用户传达一些重要的信息,以及它是否与现有的接口语法相似。如果没有,那你就不必麻烦了
不寻常的界面有一个最初的惊喜因素,但它们会导致日常使用中的挫折和错误。它们还可能导致苹果拒绝你的应用程序 实际上,我通过更改UIViewController的方向来实现这一效果。奇怪的是,当我的控制器不工作时,我让它嵌套在另一个控制器中,但当我将它设置为即时视图控制器时,它工作了 执行此操作的代码: 在UIViewController中,它是我的应用程序代理中的主视图控制器,只允许横向(如下面第二种方法中所示),我有以下功能:
-(void)goToPage:(int)page flipUp:(BOOL)flipUp {
//do stuff...
// start the animated transition
[UIView beginAnimations:@"page transition" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:flipUp ? UIViewAnimationTransitionCurlUp : UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
//insert your new subview
//[self.view insertSubview:currentPage.view atIndex:self.view.subviews.count];
// commit the transition animation
[UIView commitAnimations];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
通过使用容器视图,可以在四个方向中的任意一个方向进行卷曲。将容器视图的变换设置为所需的角度,然后通过将视图添加到容器视图(而不是没有变换帧的应用程序主视图)来执行卷曲:
NSView* parent = viewController.view; // the main view
NSView* containerView = [[[UIView alloc] initWithFrame:parent.bounds] autorelease];
containerView.transform = CGAffineTransformMakeRotation(<your angle here, should probably be M_PI_2 * some integer>);
[parent addSubview:containerView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:containerView cache:YES];
[containerView addSubview:view];
[UIView commitAnimations];
NSView*parent=viewController.view;//主要观点
NSView*containerView=[[UIView alloc]initWithFrame:parent.bounds]autorelease];
containerView.transform=CGAffineTransformMakeRotation();
[父添加子视图:containerView];
[UIView beginAnimations:nil上下文:nil];
[UIView-setAnimationTransition:UIViewAnimationTransitionUrlUp-forView:containerView缓存:是];
[containerView添加子视图:视图];
[UIView委员会];
我也在努力解决这个问题。要使卷曲从右侧或左侧开始,可以创建一个中间视图并对其进行变换。因此,假设您正在转换的视图(myView)是主窗口(parentView)的子视图:
您将在中间插入一个中间视图(在Interface Builder中很容易完成):
然后,使用以下代码将容器向左翻转90度,将转换视图向右翻转90度:
containerView.transform = CGAffineTransformMakeRotation(-M_PI_2);
myView.transform = CGAffineTransformMakeRotation(M_PI_2);
myView对用户来说仍然是竖直的,但是转换会认为它是在与左侧成90度的位置应用的
请注意,根据视图的自动缩放方式,可能需要在应用变换后修复帧大小,例如
containerView.frame = CGRectMake(0.0, 0.0, 768.0, 1024.0);
myWebView.frame = CGRectMake(0.0, 0.0, 768.0, 1024.0);
希望这有帮助。是最接近UIViewAnimationTransitionUrlLeft和UIViewAnimationTransitionUrlRight的位置。我在iOS5上尝试了fluXa的解决方案(因此我不得不使用[UIView trans…]),但它不起作用:卷曲仍然向上或向下。显然,现在的转换没有考虑视图的转换。因此,如果其他人想在iOS5上使用相同的技巧,解决方案是在两者之间添加另一个容器,并从中设置过渡动画 这是我的代码,它有点特殊,因为我想向左卷曲,但下角卷曲。就像我从笔记本上撕下一页
UIView* parent = self.view; // the main view
CGRect r = flipRectSize(parent.bounds);
UIView* containerView = [[UIView alloc] initWithFrame:r];
CGAffineTransform t = CGAffineTransformMakeRotation(-M_PI_2);
t = CGAffineTransformTranslate(t, -80, -80);
containerView.transform = CGAffineTransformScale(t, -1, 1);
[parent addSubview:containerView];
UIView* container2 = [[UIView alloc] initWithFrame:r];
[containerView addSubview:container2];
UIImageView* v = [[UIImageView alloc] initWithFrame:r];
v.image = [UIImage imageWithCGImage:contents.CGImage scale:contents.scale orientation:UIImageOrientationLeftMirrored];
[container2 addSubview:v];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[UIView transitionWithView:container2
duration:DURATION_CURL_ANIMATION
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[v removeFromSuperview];
} completion:^(BOOL finished) {
if (completion) {
completion(finished);
}
[containerView removeFromSuperview];}];});
注:
这并不罕见。完全一样。事实上,苹果做到了,只是方向相反。我正在创作一本互动的风景画书,所以我确信这部动画会将书的感觉传达给用户。上下效应适用于笔记本电脑(如notes应用程序)。但是对于一本合适的书,我需要一种不同的感觉。如果你看卷曲过渡,你会发现它分离了视图的三个角。翻过的一页只能拆开两页。卷曲沿对角线方向移动视图,而翻页仅从左向右移动。这种差别很微妙,但对用户的期望很重要。我认为你不能通过简单的变换得到你想要的变换,因为卷曲变换中的主要运动是右下角的对角运动。无论您如何旋转或变换视图,对角线运动都将保持不变,这将破坏从左向右简单卷曲的错觉。状态栏呢?-状态栏将显示在右侧-使用应用程序时?确保您的视图控制器没有嵌套,或者如果是嵌套的,则确保其父级实现了正确的方向…您要添加到containerView的视图是什么@fluXa
containerView.frame = CGRectMake(0.0, 0.0, 768.0, 1024.0);
myWebView.frame = CGRectMake(0.0, 0.0, 768.0, 1024.0);
UIView* parent = self.view; // the main view
CGRect r = flipRectSize(parent.bounds);
UIView* containerView = [[UIView alloc] initWithFrame:r];
CGAffineTransform t = CGAffineTransformMakeRotation(-M_PI_2);
t = CGAffineTransformTranslate(t, -80, -80);
containerView.transform = CGAffineTransformScale(t, -1, 1);
[parent addSubview:containerView];
UIView* container2 = [[UIView alloc] initWithFrame:r];
[containerView addSubview:container2];
UIImageView* v = [[UIImageView alloc] initWithFrame:r];
v.image = [UIImage imageWithCGImage:contents.CGImage scale:contents.scale orientation:UIImageOrientationLeftMirrored];
[container2 addSubview:v];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[UIView transitionWithView:container2
duration:DURATION_CURL_ANIMATION
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
[v removeFromSuperview];
} completion:^(BOOL finished) {
if (completion) {
completion(finished);
}
[containerView removeFromSuperview];}];});