我在默认视图的子视图中使用一个视图。我试图将它的高度和宽度设置为与超级视图相同,当它改变方向时。首先,当应用程序加载肖像模式时,此子视图采用完美的高度宽度,但当第二次更改为肖像模式时,它不会更改高度,宽度。 在负载: -当我改变方向我的视图的高度和宽度不会改变
[[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是的,我想把日历放在中心。 –