1

我的应用程序正在显示阿拉伯语文本,我希望在其中从左侧推送动画,而不是从 ios 默认提供的右侧推送动画。

在此处输入图像描述

我正在使用故事板。我创建了自定义 segue
我已经浏览了所有选项cocoacontrols但没有找到想要的。

我发现了以下几个选项:

1) CATransition
2) 动画
3) 维护视图控制器数组——这会造成很多混乱

下面的代码给出了完美的效果,但下面显示的黑色补丁是不可接受的-

在此处输入图像描述

-(void)perform {


UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];


CATransition* transition = [CATransition animation];
transition.duration = .25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom




[sourceViewController.navigationController.view.layer addAnimation:transition
                                                            forKey:kCATransition];

[sourceViewController.navigationController pushViewController:destinationController animated:NO];

[destinationController.view setBackgroundColor:[UIColor whiteColor]];

}

下面实现的代码没有黑色补丁 - 但不是所需的动画

  -(void)perform {

 UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
 UIViewController *destinationViewController = (UIViewController*)[self destinationViewController];



[sourceViewController.view addSubview:destinationViewController.view];
[destinationViewController.view setFrame:sourceViewController.view.window.frame];
[destinationViewController.view setTransform:CGAffineTransformMakeScale(0.5,0.5)];
[destinationViewController.view setAlpha:1.0];

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseOut
                 animations:^{
                     [destinationViewController.view setTransform:CGAffineTransformMakeScale(1.0,1.0)];
                     [destinationViewController.view setAlpha:1.0];
                 }
                 completion:^(BOOL finished){
                     [destinationViewController.view removeFromSuperview];
                     [sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
                 }];

   }

通过更改上面的代码 -但我没有得到想要的结果

-(void)perform{

UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationViewController = (UIViewController*)[self   destinationViewController];



   [sourceViewController.view addSubview:destinationViewController.view];
   [destinationViewController.view setFrame:sourceViewController.view.window.frame];
   [destinationViewController.view setAlpha:1.0];

[UIView animateWithDuration:0.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseOut
                 animations:^{

                     sourceViewController.view.frame =      CGRectMake(sourceViewController.view.frame.size.width*2, 0, sourceViewController.view.frame.size.width, sourceViewController.view.frame.size.height);



                 }
                 completion:^(BOOL finished){


                     [sourceViewController.navigationController pushViewController:destinationViewController animated:NO];
                 }];

}
4

2 回答 2

1

在 appDelegate.m 中使用以下代码 -applicationDidFinishLaunchingWithOptions

self.window.backgroundColor = [UIColor whitecolor];
于 2014-02-03T16:51:45.580 回答
0

这是 swift 中的自定义 segue,它使用凌乱的方式,操作视图控制器列表。无论如何,我想推送到视图控制器,但让它看起来像是一个流行音乐,我试图用各种方法来做动画,但最后 - 对我来说,这是获得我想要的最简单的方法,因为我不必维护我的代码,如果 iOS 样式发生变化等等,因为它使用一般流行 - 它应该保留与系统中的默认弹出相同。无论如何,代码:

class ReversePushSegue : UIStoryboardSegue {

    override func perform() {
        let sourceViewController = self.sourceViewController as UIViewController
        let destinationViewController = self.destinationViewController as UIViewController

        var vcs : NSMutableArray = NSMutableArray(array: sourceViewController.navigationController.viewControllers)
        vcs.insertObject(destinationViewController, atIndex: vcs.count - 1)
        sourceViewController.navigationController.viewControllers = vcs

        sourceViewController.navigationController.popViewControllerAnimated(true)

    }

}

它的作用 - 它将destinationViewController 作为倒数第二个添加到列表中,然后弹出到它..

于 2014-08-24T14:49:10.177 回答