iPhone Curl Left和Curl Right过渡
-
06-07-2019 - |
题
我正在寻找一种在iPhone上进行UIViewAnimationTransitionCurlUp
或UIViewAnimationTransitionCurlDown
过渡的方法,而不是从上到下,从左到右(或横向模式的顶部/底部)进行。我已经看到过这次问过互联网几次,但没有一个问题可以得到答案。但我觉得这是可行的。
我尝试更改View的变换和view.layer的变换,但这并没有影响过渡。由于当设备改变方向时转换发生变化,我认为有一种方法可以欺骗设备在纵向模式下使用横向转换,反之亦然?
解决方案 2
我实际上通过改变我的UIViewController的方向来实现这个效果。奇怪的是,当我的控制器不工作时,我将控制器放在另一个控制器中,但是当我将它设置为直接视图控制器时,它起作用了。
执行此操作的代码:
在UIViewController中,它是我的app委托中的主视图控制器,只允许横向(如下面的第二种方法所示)我有以下内容:
-(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];
我也很努力。要从右侧或左侧获得卷曲,您可以创建一个中间视图并对其进行转换。所以,假设你正在转换的视图(myView)是主窗口的一个子窗口(parentView):
-parentView
-->myView
您将在其间插入一个中间视图(在Interface Builder中轻松完成):
-parentView
-->containerView
--->myView
然后,使用以下代码将容器向左翻转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);
希望这会有所帮助。这是离UIViewAnimationTransitionCurlLeft和UIViewAnimationTransitionCurlRight最近的地方。
我尝试在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];}];});
注意:
- 我必须承认仿冒变换翻译(80,80)在我的脑海里没有意义,但它对iPhone来说是必要的,可能无法在iPad上运行。
- flipSizeRect翻转矩形的宽度和高度(你已经有了,对吗?)
- dispatch_after是必要的,因为我添加了容器,然后想要从层次结构中删除视图。如果我遗漏了派遣没有动画。我最好的猜测是,在我们为移除设置动画之前,我们首先需要让系统进行布局传递。 醇>
我认为除了编写自定义动画之外还有其他方法。
更重要的是,你可能不应该尝试它。卷曲和卷曲是用户界面语法的一部分,它告诉用户视图正在提升或放下现有视图。它应该像一个粘滞便笺被放下然后被删除。左<!> lt; - <!> gt;右卷曲很可能被解释为从书中翻页。这会让用户感到困惑。
每当你发现自己试图在标准API不易做的界面中做某事时,你应该问自己这种新颖的方法是否会向用户传达一些重要的东西,以及它是否与现有的界面语法类似。如果没有,那么你不应该打扰。
不寻常的界面有一个令人惊叹的因素,但它们会导致日常使用中的挫折和错误。它们还可能导致Apple拒绝您的应用。