我正在为Ipad中的所有方向开发应用程序....但是在开发期间我只做了横向模式..但是我想改变所有可能的方向......这里我遇到了一些问题.... 这是代码......
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
//return YES;
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortrait);
}
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight)
{
\\Here I did my stuff..
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
\\Here I did my stuff..
}
}
问题是,当模拟器启动时,如果itz处于横向模式,我得到了适当大小的视图,但如果模拟器处于potrait模式,我就无法得到我想要的...如果我改变模拟器的方向我得到正确的视图大小......
答案 0 :(得分:1)
这是面临的同样问题。 我通过这样做解决了这个问题:
首先更改此功能:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
然后在viewDidLoad函数中,您可以检查设备是横向还是纵向。
-(void)viewDidLoad
{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
//landscape view code
}
else
{
//portrait view code
}
}
hope this will help