0

編集:うわー、私はなんてばかだ。わかりやすくするために、Facebookのネイティブアプリの機能について説明したいと思います。右上と左上をタッチすると、中央部分が左または右に入り、サイドバーメニューが表示されます。

右上隅にボタンがあるphonegapアプリがあります。以下のコードを参考にしてください。

Portion of HTML:

<body>
<div id="header"><!--Button goes here--></div>
<div id="menu">
    <ul>
        <li> Option 1</li>
        <li> Option 2</li>
    </ul> 
</div>
<div id="page">
     Some contents in the page.
</div>
</body>

Javascript:
var move,x=0; //global vars

function buttonTouched() { //code for button ontouchstart event
    move = $("#menu").css('width');
    if(x==0) {
        $("#menu").animate({'left':'-='+move},'250');
        $("#page").animate({'left':'-='+move},'250');
        x=1;
    }
    else if(x==1) {
        $("#menu").animate({'left':'+='+move},'250');
        $("#page").animate({'left':'+='+move},'250');
        x=0;
    }
}

ボタンをタッチすると、「menu」divが左にスライドし(jquery animateを使用)、「page」divの一部が左に移動します。アニメーション効果のあるObjectiveCコードを使用して、ネイティブアプリでこの効果を複製するにはどうすればよいですか?

ありがとう

4

1 に答える 1

1

UIViewanimateWithDurationクラスのメソッドを見てください。

メニューがmenuViewという名前のUIViewであり、ビューコントローラの画面外に配置されているとします。次に、次のようなことを行うことができます。

[UIView animateWithDuration:0.6
                          delay:0.0
                        options:UIViewAnimationCurveEaseOut
                     animations:^{
                         CGRect oldFrame = self.view.frame;
                         xOffset = menuView.frame.width;
                         self.view.frame = CGRectOffset(oldFrame, xOffset, 0);
                     }];
于 2013-02-21T08:38:30.867 に答える