在viewcontroller里加上这句:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];//屏幕旋转的通知
在通知的方法里加上这句:
-(void)statusBarOrientationChange:(NSNotification*)no{ NSDictionary* ntfDict = [no userInfo]; self.collectionView.frame = CGRectMake(0, 0, DF_WIDTH, DF_HEIGHT);//如果要重置view的大小的话,一定要加上这句 UIDeviceOrientation interfaceOrientation = [UIDevice currentDevice].orientation; if (interfaceOrientation == UIDeviceOrientationPortrait || interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) { //翻转为竖屏时 count = 3; [self.collectionView reloadData]; }else if (interfaceOrientation==UIDeviceOrientationLandscapeLeft || interfaceOrientation == UIDeviceOrientationLandscapeRight) { //翻转为横屏时 count = 5; [self.collectionView reloadData]; } }
更全总结: [iOS]关于iOS中界面视图横屏/竖屏切换的问题总结:http://blog.csdn.net/lqq200912408/article/details/51088987
时间: 2024-10-11 13:32:53