首先重写UIViewController方法:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return YES;
}
你也可以根据toInterfaceOrientation的不同值来判断是否允许旋转。这个传入参数有四种取值:
UIInterfaceOrientationLandscapeLeft 横向Home键在左
UIInterfaceOrientationLandscapeRight 横向Home键在右
UIInterfaceOrientationPortrait 正常
UIInterfaceOrientationPortraitUpsideDown 反向Home键在上
可以在下面的方法中处理旋转后要重画的组件,或者重载另一个NIB文件。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
// 重新加载一个Nib文件
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[[NSBundle mainBundle] loadNibNamed:@"LoginViewLandscape" owner:self options:nil];
}else {
[[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil];
}
// 重写Toolbar
// Set Toolbar
UIBarButtonItem *newChat = [[UIBarButtonItem alloc] initWithTitle:@"新增" style:UIBarButtonItemStylePlain target:self action:@selector(createChat:)];
UIBarButtonItem *refresh = [[UIBarButtonItem alloc] initWithTitle:@"刷新" style:UIBarButtonItemStylePlain target:self action:@selector(refresh:)];
UIBarButtonItem *deleteChat = [[UIBarButtonItem alloc] initWithTitle:@"删除" style:UIBarButtonItemStylePlain target:self action:@selector(deleteChat:)];
self.deleteItem = deleteChat;
self.deleteItem.enabled = NO;
UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
fixedItem.width = 155;
}else {
fixedItem.width = 75;
}
NSArray *toolBarItems = [[NSArray alloc] initWithObjects:newChat, fixedItem, refresh, fixedItem, self.deleteItem, nil];
[self setToolbarItems:toolBarItems];
[toolBarItems release];
[newChat release];
[deleteChat release];
[fixedItem release];
[refresh release];
}
如果你使用了Interface Builder工具,并不一定要重写界面,工具有自动处理的方式。
方法:
1 选中你的组件
2 Command+3 打开View Size配置界面 你会看到有一项叫:Autosizing 如下图:
3 设置组件自动缩放情况
左边的框,中间有个小框,里面是指垂直和水平是否缩放,外面是指位置。根据各自应用调整,调整后在右边的小动画里能看到效果。
下面是两个实现了旋转响应的效果图,一个是重新加载了Nib文件,一个是用Interface Builder工具自动缩放。
分享到:
相关推荐
ios6.0的屏幕旋转机制和之前的版本有很大的不同了,这个资源就是我自己写的支持ios6.0屏幕旋转的例子。是navigationController作为rootViewController的例子,通过重写一个navigationController类来实现。对屏幕旋转...
这是一款使用jQuery和多张图片制作的炫酷iPhone手机3D旋转互动特效插件。该3d旋转特效中用户可以使用鼠标360度旋转iPhone手机,从各个角度观察手机的细节。该3d旋转特效共4种效果。
兼容 IPhone8 兼容 IPhone8 兼容 IPhone8 兼容 IPhone8 兼容 IPhone8 兼容 IPhone8 兼容 IPhone8 兼容 IPhone8
实现客户端可以在Iphone4和Iphone5上屏幕正常显示
如何用cocos2d制作iphone游戏:旋转炮塔,大家一起动手试试
java 图片压缩 iphone拍照上传旋转问题处理,压缩工具类 首先导入jar 包,通过imgxz获取图片是否旋转属性,在调用旋转方法,旋转过来,然后在进行压缩
iphone手机屏幕主流尺寸 ai文件,仅供学习参考使用。谢谢!
iPhone 6屏幕揭秘.pdf
iphone立体旋转iphone立体旋转iphone立体旋转iphone立体旋转
【带腔体的光电封装技术】iphonex屏幕封装技术.pdf【带腔体的光电封装技术】iphonex屏幕封装技术.pdf【带腔体的光电封装技术】iphonex屏幕封装技术.pdf【带腔体的光电封装技术】iphonex屏幕封装技术.pdf【带腔体的...
你必须熟悉iPhone或Android主屏幕概念。你有窗口。有各种实用的图标。如果图标的数量超过菜单上的空间,创建了新的一页。通过刷卡用手指,你可以看到下一个页面,并有互动的图标。
响应按下,滑动,抬起,双击事件 这是照着书上的例子打的代码,可以正常运行。 初学者请进,高手请退避 touchesBegan touchesMoved touchesEnded touchesCancelled
Android 实现iphone主屏幕文件夹展开合并效果(OpenFolder)
jQuery CSS仿iPhone手机滑动解锁屏幕
iphone X iphone 8 原型框 iphone X iphone 8 原型框
iPhone狂:约会iPhone
忘记iPhone密码锁、Apple ID密码找不回来了,一键解锁iPhone屏幕密码锁,移除Apple ID
超绚丽的苹果手机屏幕保护 超绚丽的苹果手机屏幕保护 超绚丽的苹果手机屏幕保护 超绚丽的苹果手机屏幕保护
CSS3 做出iPhoneX手机屏幕背景和页面背景图片同时切换特效