首页 文章

支持iOS 7 iPad中的横向和纵向方向

提问于
浏览
0

任何人都可以解释我如何使用自动布局或编程方式在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);

}

}

2 回答

  • 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,那么你可以同时拥有这两个 .

  • 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);
    }
    

    }

    现在,控件在两个方向上都能正常工作

相关问题