我找了几篇关于 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];
}
任何帮助都会很有用