我在默認視圖的子視圖中使用一個視圖。我試圖將它的高度和寬度設置爲與超級視圖相同,當它改變方向時。首先,當應用程序加載肖像模式時,此子視圖採用完美的高度寬度,但當第二次更改爲肖像模式時,它不會更改高度,寬度。 在負載: -當我改變方向我的視圖的高度和寬度不會改變
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
方法: -
- (void) orientationChanged:(NSNotification *)note
{
UIDevice * device = note.object;
switch(device.orientation)
{
case UIDeviceOrientationPortrait:
NSLog(@"Portrait");
NSLog(@"View Height %f",self.view.frame.size.height);
NSLog(@"View Width%f",self.view.frame.size.width);
view1.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"View1 Height %f",view1.frame.size.height);
NSLog(@"View1 Width%f",view1.frame.size.width);
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@" LanScapRight");
view1.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.height, self.view.frame.size.width);
break;
case UIDeviceOrientationLandscapeLeft:
NSLog(@" LandScapLeft");
view1.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
default:
view1.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"Default");
//view1.frame=CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.height, self.view.frame.size.width);
break;
};
}
輸出:-(問題)
2016-02-20 01:29:15.907 Editing[4999:95632] Portrait
[![2016-02-20 01:29:15.910 Editing\[4999:95632\] View Height 568.000000
2016-02-20 01:29:15.910 Editing\[4999:95632\] View Width320.000000
2016-02-20 01:29:15.911 Editing\[4999:95632\] View1 Height 568.000000
2016-02-20 01:29:15.912 Editing\[4999:95632\] View1 Width320.000000
2016-02-20 01:29:39.090 Editing\[4999:95632\] LanScapRight
2016-02-20 01:29:40.364 Editing\[4999:95632\] Default
2016-02-20 01:29:41.645 Editing\[4999:95632\] LandScapLeft
2016-02-20 01:29:41.646 Editing\[4999:95632\] Default
2016-02-20 01:29:43.316 Editing\[4999:95632\] Portrait
2016-02-20 01:29:43.317 Editing\[4999:95632\] View Height 320.000000
2016-02-20 01:29:43.317 Editing\[4999:95632\] View Width568.000000
2016-02-20 01:29:43.317 Editing\[4999:95632\] View1 Height 320.000000
2016-02-20 01:29:43.318 Editing\[4999:95632\] View1 Width568.000000]
你有沒有正當理由不使用autolayout? –
smit是你的問題解決? –
@ elio.d是的,我想把日曆放在中心。 –