2011-07-09 8 views
0

buttonclickイベントの後に、ビューの側面からメニューをスライドさせたいとします。別のButtonclick後にメニューがiOS別のビューの側面からUIView(メニュー)をスライドさせます

私はCATransitionで実験が、私はこの問題を解決することはできませんが...

CATransition *animation = [CATransition animation]; 
[animation setDuration:1]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromBottom]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]] ; 

[[menuView layer] addAnimation:animation forKey:@"@asdf"];   
[menuView setCenter:CGPointMake([menuView center].x, [menuView center].y + 450)]; 

それは少し仕事...大きなビューから滑らせるべきであるが、私はやりました理由を理解できません。:/

+0

。 – jtbandes

+0

「それは少しうまくいく」とはどういう意味ですか?それは何をしたのですか?それはあなたが望むものとどのように違うのですか? –

+0

ok "メニュー"が正しく表示されていますが、アルファブレンディング効果がありますが、理解できません。 – Phil

答えて

0

ViewDeckのようなコントローラでは、これを実行できます。

: 私はこの他に何が追加されるべきかわかりません。これは、FacebookやPathのように、クリックしたときにスライドして再びクリックされるときにスライドするボタンによって制御されるメニューを追加するオープンソースコードです。あなたはまた、スライドでタッチイベントを取得しています。

ここにgithubページで使用する方法の例があります:https://github.com/Inferis/ViewDeck#how-to-use-itと、ソースコードで利用可能ないくつかのプロジェクト例があります。

+0

提案コードはどのように役立ちますか?単なるリンク以上のものになるように答えを広げてください。そうしないと、解消される可能性があります。 –

0

自分で実装する場合は、カスタムビューを作成し、ビューコントローラのボタンのボタンクリックイベントを追加することができます。

また、カスタムビューが表示されるかどうかを識別するブール値変数を作成します。メニュービューが表示されていない場合

クリックで、その後、次の操作を行います。あなたはこれまでにしようとしているものを投稿する必要があります

-(void)viewDidLoad 
{ 
    ... 

    // --------------------------------------------- 
    // create the custom menu view off screen 
    // --------------------------------------------- 
    menuView = [[MenuView alloc] initWithFrame:CGRectMake(-320, 0, 320, 480)]; 
    menuView.alpha = 0; // hide it so it doesn't show at the start, only show when slide in 

    [self.view addSubview:menuView]; 

    ... 
} 

-(void)toggleMenu 
{ 
    if(menuIsVisible) 
    { 
     menuIsVisible = NO; 

     [self hideMenu]; 
    } 
    else 
    { 
     menuIsVisible = YES; 

     [self showMenu]; 
    } 
} 

-(void)hideMenu 
{ 
    [UIView animateWithDuration:0.5 animations:^{ 
     // note CGAffineTransforms doesn't use coordinates, they use offset 
     // so an offset of (0,0) would bring the menuView back to the coordinate 
     // when it was first instantiated, in our case, (-320, 0). 
     menuView.transform = CGAffineTransformMakeTranslation(0,0); 
    } completion:^{ 
     // hide the menu 
     menuView.alpha = 0; 
    }]; 
} 

-(void)showMenu 
{ 
    // show the menu 
    menuView.alpha = 1; 

    [UIView animateWithDuration:0.5 animations:^{ 
     // note CGAffineTransforms doesn't use coordinates, they use offset 
     // so an offset of (320,0) from coordinate (-320,0) would slide the 
     // menuView out into view 
     menuView.transform = CGAffineTransformMakeTranslation(320,0); 
    }]; 
} 
関連する問題