繁体   English   中英

在segue之前如何制作动画

[英]how to make animation before a segue

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

这是图片 在此处输入图片说明

应用启动时,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];


}

自定义Segue类:

-(void)perform
{

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

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


}

任何帮助都会有用

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM