正确缩放图像和按钮方向,适用于横向和纵向模式ipad

时间:2013-12-02 07:25:48

标签: ios objective-c ipad uiimageview landscape-portrait

开发了一个在纵向模式下看起来很好的ipad应用程序。如下所示:portrait mode

但是,在横向模式下看起来不太好。 Landscape mode

如何使这个正确?我启用了autolayout选项......

注意:我正在添加背景iamge

self.view.backgrounfcolor = [UIColor colorwithparttenimage:[UIImage imageNamed:@"ems.png"]];

1 个答案:

答案 0 :(得分:0)

这里仅供参考。刚刚从我的存储库中复制和粘贴。相应地改变。

-(void)viewWillAppear:(BOOL)animated{
    [[self navigationController] setNavigationBarHidden:YES animated:NO];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [self orientationChanged:(UIInterfaceOrientation)[[UIDevice currentDevice]orientation ]];

}

-(BOOL) supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

-(BOOL) shouldAutorotate{
    return YES;
}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [self orientationChanged:toInterfaceOrientation];
}


-(void) orientationChanged: (UIInterfaceOrientation)orientation{

    if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){
        NSLog(@"Changed Orientation To Portrait");
       // self.viewPortrait.hidden = NO;
     //   self.viewLandscape.hidden = YES;
         [self portraitOrientation];
    }

    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
        NSLog(@"Changed Orientation To Landscape");
        //self.viewPortrait.hidden = YES;
        //self.viewLandscape.hidden = NO;

         [self landscapeLeftOrientation];
        /*
         if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
         NSLog(@"Changed Orientation To Landscape left");
         [self landscapeLeftOrientation];
         }else{
         NSLog(@"Changed Orientation To Landscape right");
         [self landscapeRightOrientation];
         }
         */

    }

}
-(void)landscapeLeftOrientation{

    // Rotates the view.
    NSLog(@"LandscapeLeft");

    CGAffineTransform transform = CGAffineTransformMakeRotation(0);
    self.view.transform = transform;
    // Repositions and resizes the view.
    CGRect contentRect = CGRectMake(0, 0, 480, 320);
    self.view.bounds = contentRect;
    self.view.bounds = contentRect;

    self.img.center = CGPointMake(256, 23);
    self.btnHome.center = CGPointMake(437.0f, 23.0f);
    self.messageList.frame = CGRectMake(54, 54, 405,200);
    self.txtMessage.frame = CGRectMake(26, 262, 355, 30);
    self.btnSendMsg.frame = CGRectMake(399, 262,61,32);
}

-(void)portraitOrientation{

    // Rotates the view.
    CGAffineTransform transform = CGAffineTransformMakeRotation(0);
    self.view.transform = transform;
    // Repositions and resizes the view.
    CGRect contentRect = CGRectMake(0, 0, 320, 480);
    self.view.bounds = contentRect;

    self.img.center = CGPointMake(160.0f, 24.0f);
    self.btnHome.center = CGPointMake(277.0f, 24.0f);
    self.messageList.frame = CGRectMake(3,49, 341,321);
    self.txtMessage.frame = CGRectMake(3, 378, 235, 30);
    self.btnSendMsg.frame = CGRectMake(256, 378,61,32);

}