2010-12-29 16 views
1
-(IBAction) takeNextStep : (id) sender 
{ 
    SecondViewController *varSecondViewController =[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
} 

私はカスタムボタンを持っているので、右から左へ(後ろに)左から右(前方)へのスライドをデフォルトから変更する方法を教えてください。しかし、右から左にスライドするので、ユーザーの混乱を招く。戻るボタンのためにアニメーションを左から右にスライドさせることから!ナビゲーション

ありがとう!あなたはこのようなものを使用する場合があります

+0

こんにちは、この問題に直面して、私の2番目のビューを最初のビューにスライドさせることができません! 現在:左から右へスライド(行くfwd) 私が必要なもの:右から左へスライド –

答えて

2

...

(必要が< QuartzCore/QuartzCore.h>)

右から左へのビューをスライドカスタム関数をだ
- (void)switchTwoViews:(UIView *)view1 otherView:(UIView *)view2 direction:(int)directionRL{ 
    view2.bounds = CGRectMake(0, 0, 480, 320); 
    visibleView = view2; 
    // remove the current view and replace with view1 
    [view1 removeFromSuperview]; 
    [currentOptionsView addSubview:view2]; 

    // set up an animation for the transition between the views 
    CATransition *animation = [CATransition animation]; 
    [animation setDuration:0.5]; 
    [animation setType:kCATransitionPush]; 
    if (directionRL == 0) { 
     [animation setSubtype:kCATransitionFromRight]; 
    } else { 
     [animation setSubtype:kCATransitionFromLeft]; 
    } 

    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

    [[currentOptionsView layer] addAnimation:animation forKey:@"SwitchToView"]; 
} 

(方向= 0 )、またはその逆(direction = 1)である。

お試しください。楽しい。

+0

ありがとう! –

+0

これは6つのエラーを表示しますkCATransitionX ... QuartzCoreと共にすべてのヘッダーを含める必要があることを教えてください。 –

+0

#import のみであるべきです... UIKitが必要かどうか確かめてください。 –

4

Xenの回答と同様に、the sample code hereをダウンロードしてください。

// get the view that's currently showing 
UIView *currentView = self.view; 
// get the the underlying UIWindow, or the view containing the current view 
UIView *theWindow = [currentView superview]; 

UIView *newView = aTwoViewController.view; 

// remove the current view and replace with myView1 
[currentView removeFromSuperview]; 
[theWindow addSubview:newView]; 

// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"]; 
関連する問題