私は新しいios開発者です。私は2つのビューを追加したいios appを作成したいと思います。最初にappを起動すると、最初のビューが表示されます。ボタンがあります。タップ・オン・ボタンを押すと、2番目のビューが画面に左から右に表示され、フル・スクリーンではなく画面の半分に表示されます。 どうすればいいですか? ありがとうございます。uiビューの左から右への変換
0
A
答えて
1
実際には、UIViewのanimateWithDurationラッパーの助けを借りて非常に簡単です。あなたがブロックに慣れていない場合でも、これは優れた学習機会です。
まず、.hの二つのUIViewオブジェクトを宣言し、あなたがボタンにフックアップするメソッドを定義します.Mで今
@interface Example : UIViewController
{
UIView *_view1;
UIView *_view2;
}
@property (nonatomic, retain) UIView *view1;
@property (nonatomic, retain) UIView *view2;
-(IBAction)animateViews:(id)sender;
@end
を、(あなたのアクションを定義し、それはへのリターンタイプの変更です気づきます)のボイドが、それは署名が同じままだ:
#import "Example.h"
@implementation Example
@synthesize view1 = _view1;
@synthesize view2 = _view2;
-(void)viewDidLoad {
//alloc and init views, add to view
self.view1 = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view2 = [[UIView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width, 0, self.view.bounds.size.width/2, self.view.bounds.size.height)];
//Set the background color so we can actually see the views, the first will be grey, the second, black.
[self.view1 setBackgroundColor:[UIColor grayColor]];
[self.view2 setBackgroundColor:[UIColor darkTextColor]];
//add subview to main view
[self.view addSubview:self.view1];
[self.view addSubview:self.view2];
[super viewDidLoad];
}
-(void)animateViews:(id)sender {
/*I absolutely love the UIView animation block,
it's possibly the most helpful thing in terms of animation apple could have made.
Any property changed inside this block (in this case, the frame property),
is automatically animated for the duration you specify.
It's even got a built in completion block! So cool.*/
[UIView animateWithDuration:2.5 animations:^{
[self.view1 setFrame:CGRectMake(0, 0, self.view.bounds.size.width/2, self.view.bounds.size.height)];
[self.view2 setFrame:CGRectMake(self.view.bounds.size.width/2, 0, self.view.bounds.size.width/2, self.view.bounds.size.height)];
}];
}
@end
これは、画面の半分を取るために、最初のビューのフレームをアニメーション化して、ソートの中に飛ぶと他を取るために2番目のビューをアニメーション化すべきですハーフ。あなたはそれを実行する前に、そのIBActionをXIBのボタンに接続してください。
関連する問題
- 1. 右から左へのUIガイドライン?
- 2. 右端値から左端値への変換Visual Studio
- 3. ハスケルの左から右への連鎖方法(右から左へと反対)
- 4. UIとテキストの断続的な右から左へのミラーリング
- 5. 右から左へJqueryスライドタブ
- 6. カール左から右へ
- 7. Windowsアプリケーションの右から左へのコントロール!
- 8. 右から左への電子メール
- 9. プライムフェイス右から左へのサポート
- 10. Iphoneと右から左へのテキスト
- 11. IE9レンダリング左から右へのマーク
- 12. 右から左への表示
- 13. Liferayポートレットの右から左へ
- 14. 可変幅のdivの右から左へのスライドアウト。
- 15. UITableView MoveRowボタンの位置が右から左へ変更する
- 16. ハスケル関数は左から右へ
- 17. 画像CSSで右から左へスクロール
- 18. wxWidgets右から左へ方向
- 19. Jquery Image右から左へスライド
- 20. VI(VIM):右から左へ削除/変更しますか?
- 21. C言語の右から左および左から右への連想の影響は何ですか?
- 22. スカラどちらのマップ右または左へ左
- 23. 右から左UILabels
- 24. IOS:UIViewAnimationTransitionCurlUp右から左
- 25. ContextMenu右から左
- 26. ヒストグラムを左から右に変更
- 27. iPhoneのビューを左から右にアニメートする方法は?
- 28. 棒グラフの右から左への方向を変更する方法は?
- 29. 上から下への左→右の配置要素
- 30. Cの右から左への解析文字列
あなたはviewcontrollerとxibを認識していますか、ボタンのアクションを作成する方法はありますか?現在使用しているXCodeと、このアプリケーションを作成するiOSバージョン。 – Ravin