在横向模式下使用UIViewAnimationTransitionFlipFromLeft的iPhone Flip Animation [英] iPhone Flip Animation using UIViewAnimationTransitionFlipFromLeft in landscape mode

查看:304
本文介绍了在横向模式下使用UIViewAnimationTransitionFlipFromLeft的iPhone Flip Animation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个iPhone应用程序,我在其中实现了一个动画UIViewAnimationTransitionFlipFromLeft。这里我的应用程序在纵向模式下工作正常。它正在执行与指定相同的动画,即从左到右翻转。

I am working on one iPhone application in which I implemented one animation UIViewAnimationTransitionFlipFromLeft. Here my application works fine in the Portrait mode. It is doing the same animation as specified means Flip from Left to Right.

但是当我在横向模式下执行此UIViewAnimationTransitionFlipFromLeft时,它不会从左向右旋转。而不是它从上到下旋转。这是非常关键的问题。你可以帮我解决这个问题。

But when I am doing this UIViewAnimationTransitionFlipFromLeft in landscape mode then it is not rotating from left to right. Instead of it is rotating from top to bottom. This is really critical issue. Can you help me out to solve this.

我用于iPhone应用程序旋转视图的代码如下:

The code I am using for iPhone application to rotate the view is as follows:

   CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view.window cache:NO];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    [UIView commitAnimations];
    [self.navigationController pushViewController:objSecond animated:YES];

谢谢,
最好的问候,
Gurpritsingh Saini

Thanks, Best Regards, Gurpritsingh Saini

推荐答案

如果您使用的是iOS 4.0或更高版本,以下内容将完全符合您的要求(我只是测试了它以确保)

If you are using iOS 4.0 or later, the following will do exactly what you want (I just tested it out to make sure)

NewView *myNewView = [[NewView alloc] initWith.....];
[UIView transitionFromView:self.view toView:myNewView.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
//[self.navigationController pushViewController:myNewView animated:NO];
[myNewView release];

编辑:我正在改变上面的代码(没什么新东西,只是评论出导航控制器因为没有必要这样做。)

I'm changing the above code a bit (nothing new, just commenting out the navigation controller because it's not necessary for this).

所以有几种方法可以解决这个问题(就跟踪下一个视图而言),但这是最容易的可以想到。你已经可以从视图1切换到2,所以我将解释如何从2到10(或者你需要多少)。

So there are several ways to go about this (as far as keeping track of the next view), but this is the easiest I can think of. You can already switch from view 1 to 2, so I'm going to explain how to get from 2 to 10 (or however many you need).

基本上,视图转换持续时间过长 viewDidLoad 以捕获调用以转到下一个视图。所以我们需要做的是设置一个定时器,等待并发送一个方法以便稍后切换。所以这是您在视图2(以及3和4等)中看到的代码。

Basically, the view transition lasts too long for viewDidLoad to catch a call to go to the next view. So what we need to do is set up a timer that waits and sends a method to switch at a later time. So this is the code you would see in view 2 (and 3 and 4, etc.).

- (void)viewDidLoad {
    // this gets called before animation finishes, so wait;
    self.navigationController.delegate = self;
    // you will need to set the delegate so it can take control of the views to swap them;
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(switchView) userInfo:nil repeats:NO];
}

我只等待1秒,直到我调用switch方法,但如果你是在视图中加载很多,您可能需要等待一段时间。 1.5秒应该绰绰有余,但你可以玩它来看看它的工作原理和不起作用。

I only wait 1 second until I call the switch method, but if you are loading a lot into your views, you may want to wait a bit longer. 1.5 seconds should be more than enough, but you can play around with that to see where it works and doesn't work.

接下来,你必须调用下一个视图在 switchView 方法中。

Next, you have to call the next view in the switchView method.

- (void)switchView {
    NextView *myNextView = [[NextView alloc] initWith ... ];
    [UIView transitionFromView:self.view toView:nextView.view duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil];
    [nextView release];
}

这对我来说非常合适。为了确保我获得新视图,我为每个视图分配了标签,并在每个视图的 viewDidLoad 方法中添加了UILabel作为子视图,并且每个都显示了其视图的编号。所以希望这就是你所需要的。我确信你需要做更复杂的事情,但这会给你动画和逻辑,让你获得你想要的外观。 (在旁注中, viewDidAppear 在执行此操作时似乎没有被调用,因此可能需要从 viewDidLoad手动调用它如果你真的需要使用它,但除此之外它工作正常)

This worked perfectly for me. Just to make sure I was getting new views, I assigned tags to each view and added UILabels as subviews in each view's viewDidLoad method and each showed the number of its view. So hopefully this is what you needed. I'm sure you have more complex things you will need to do, but this will give you the animation and logic you need to get the look you want. (on a side note, viewDidAppear doesn't seem to get called when doing this, so it might be necessary to call it manually from viewDidLoad if you really need to use it, but otherwise it works fine)

这篇关于在横向模式下使用UIViewAnimationTransitionFlipFromLeft的iPhone Flip Animation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆