1

SO やその他の情報源に関する記事をいくつか探しましたが、答えが見つかりません。この質問は複雑なものになります。まず、私が持っているもの: 2 つのビュー コントローラー (VC1 と VC2 と呼びましょう)、および各 VC に 1 つのボタン (B1 と B2 と同じように呼びましょう)。

ここに画像がありますここに画像の説明を入力

アプリの起動時に、スクリーンショットのように B1 が画面の右端から中央の位置にスライドします。このコードを以下に追加します。これを作りたい: B1 をクリックすると、B1 が画面の境界の後ろにスライドし、セグエが実行され、B2 ボタンが右から中央にスライドします (B! ボタンのように)。どうすればこれを作ることができますか?カスタムセグエクラス、または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];


}

どんな助けも役に立ちます

4

1 に答える 1

0

B1 を押したときにセグエを呼び出す代わりに、ヘルパー アクション メソッドを呼び出します。このメソッド内でスライディングを実行し、performSegueWithIdentifier を使用してセグエを呼び出します。ボタンを後方にスライドするには、viewWillAppear でその位置を確認し、必要に応じて後方に移動します。

于 2013-07-01T15:18:57.173 に答える