Spa*_*Dog 3 iphone iphone-sdk-3.0
我有一个应用程序,其中UIToolBar将始终位于屏幕的底部.无论设备方向如何.
工具栏必须具有相同的屏幕宽度,并始终在底部对齐.
如果设备旋转,工具栏必须采用新的宽度并继续在底部对齐.
有没有办法以编程方式执行此操作?
谢谢你的帮助.
首先,自动旋转可能有点棘手.例如,如果您使用的是UITabBarController,则需要对其进行子类化并添加适当的委托方法.在真正潜入之前,您应该通过Apple文档和Google了解自动轮换.
要具体回答您的问题,以下是您需要声明UIToolbar以便在设置应用程序时自动旋转的方法:
// I keep this definition in a file called constants.h since I use it a lot
#define SCREEN_FRAME [[UIScreen mainScreen] applicationFrame]
UIToolbar *tb = [[[UIToolbar alloc]init]autorelease];
// this frame will position a toolbar at the bottom of the screen
tb.frame = CGRectMake(0,
SCREEN_FRAME.size.height-tb.frame.size.height,
SCREEN_FRAME.size.width,
tb.frame.size.height);
//Setting the auto-resizing mask will make the toolbar resize when the viewController
//it resides in rotates.
tb.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7114 次 |
| 最近记录: |