にメソッドを追加できますAppDelegate
。
- (BOOL) ISIPAD {
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
}
そして、アニメーションを作るたびにそれを参照してください。クラスに画面の幅などの変数がある場合は、viewDidLoad
、またはinit
メソッドでこれを確認するだけで済みます。次に、動的変数を使用してアニメーションを実行できます。画面の中央にボタンを配置するには、次のようにします。
[UIView animateWithDuration:1.0 animations:^{
UIButton *yourButton;
yourButton.frame = (CGRect){.origin = CGPointMake(screenwidth/2.0f-yourButton.frame.size.width/2.0f, screenheight/2.0f - yourButton.frame.size.height/2.0f), .size = yourButton.frame.size};
}];
init
orメソッドで screenvariables が設定されていることを考慮するviewDidLoad
と、これによりボタンが画面の中央に配置されます。