如何在segue之前制作动画

时间:2013-07-01 12:24:37

标签: iphone ios animation view segue

我在SO和其他来源上找了几篇文章,但找不到答案。这个问题将是一个复杂的问题。首先,我有:两个视图控制器(让我们称之为VC1和VC2),以及每个VC上的一个按钮(让我们以与B1和B2相同的方式调用它们)。

这是图片enter image description here

当应用程序启动时,B1从屏幕右边框滑动到中间位置,如截图; 我将在下面添加以下代码。我想要这样做:当我点击B1时,B1滑动屏幕边框后面,执行segue,然后B2按钮从右到中滑动(就像B!按钮一样)。我该怎么做?我必须在自定义segue类或一些UIView方法中执行此操作吗?

在更多问题上,如果我们点击B1(它滑过左边界),我们就在VC2。如果我单击后退按钮(屏幕截图上的底部按钮),我将看到白色屏幕(因为B1的中心坐标约为-100)。我怎么能防止这种情况?

VC1代码

#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *buttonOne;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    CGPoint startPossitionForButton = CGPointMake(345, 220);
    self.buttonOne.center = startPossitionForButton;


    [self slideButton];

}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    [self slideButtonOffScreen];
}





-(void)slideButton
{
    [UIView animateWithDuration:0.3 animations:^{

    CGPoint endPossitionForButton = CGPointMake(155, 220);

    self.buttonOne.center = endPossitionForButton;

}];


}


-(void)slideButtonOffScreen
{
    [UIView animateWithDuration:0.3 animations:^{

        CGPoint endPossitionForButton = CGPointMake(-100, 220);

        self.buttonOne.center = endPossitionForButton;

    }];


}

VC2代码

@interface VC2 ()
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UIButton *buttonTwo;

@end

@implementation VC2


- (IBAction)back:(id)sender {

    [self.navigationController popViewControllerAnimated:NO];


}



-(void)slideButton
{
    [UIView animateWithDuration:0.3 animations:^{

        CGPoint endPossitionForButton = CGPointMake(155, 220);

        self.buttonTwo.center = endPossitionForButton;

    }];


}


- (void)viewDidLoad
{
    [super viewDidLoad];


    CGPoint startPossitionForButton = CGPointMake(345, 220);
    self.buttonTwo.center = startPossitionForButton;


    [self slideButton];


}

Custom Segue class:

-(void)perform
{

    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;

    [src.navigationController pushViewController:dst animated:NO];


}

任何帮助都会有用

1 个答案:

答案 0 :(得分:0)

而不是在按B1时调用segue调用辅助操作方法。在此方法内部执行滑动并使用performSegueWithIdentifier调用segue。 要向后滑动按钮,请在viewWillAppear中检查其位置,并在必要时将其移回。