任何人都可以解释我如何使用自动布局或以编程方式在iOS 7 iPad中支持横向和纵向方向。
我尝试过@“将以方式旋转方法”并自动布局..但这些都不能正常工作。
不知道我犯了什么错误
请查看以下代码以供参考并更正我
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"Landscape left");
NSLog(@"Landscape left : %@",LoginBackgroundView);
LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 1024, 768);
LoginViewObj.LoginBackgroundView.frame =CGRectMake(346, 228, 337, 300);
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"Landscape right");
LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 1024, 768);
LoginViewObj.LoginBackgroundView.frame =CGRectMake(346, 228, 337, 300);
} else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
NSLog(@"Portrait");
NSLog(@"potrait : %@",LoginBackgroundView);
LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 768, 1024);
LoginViewObj.LoginBackgroundView.frame =CGRectMake(0, 330, 337, 300);
} else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
NSLog(@"Upside down");
LoginViewObj.loginBackgroundImage.frame= CGRectMake(0 , 0, 768, 1024);
LoginViewObj.LoginBackgroundView.frame =CGRectMake(0, 330, 337, 300);
}
}
答案 0 :(得分:0)
(旧的方式)支持< = iOs 5 ..的所有接口方向 把它放在你的viewController
中-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
(当前的方式)支持> = iOs 6的所有接口方向.. 将这些放在viewController中,然后在目标设置的常规'(第一)标签中选择支持的方向......
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0){
return YES;
}
- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0){
return UIInterfaceOrientationMaskAll;
}
如果你一直瞄准iOs5,你可以同时拥有这两个。
答案 1 :(得分:0)
通过此
获得解决方案 -(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
// here for landscape mode frames
}
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
LoginBackgroundView.frame =CGRectMake(200, 330, 337, 300);
loginBackgroundImage.frame= CGRectMake(0 , 0, 768, 1024);
loginBackgroundImage.image = [UIImage imageNamed:@"Login_potrait.png"];
footerView.frame= CGRectMake(0, 980,768, 50);
logoImage.frame = CGRectMake(220, 197, 258, 105);
}
}
现在控件在两个方向上都能正常工作