2015-01-09 36 views
0

我一直在试图设置一个imageView,而不会让用户看到它改变,当他们从风景旋转到肖像模式。以编程方式设置图像视图,而用户看不到它更改?

willAnimateRotationToInterfaceOrientation方法,我重新设置图像到合适的图像(取决于它是否在横向模式或纵向模式:

if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
    NSLog(@"Going to Portrait Mode."); 

    UIImage *footerImage = [UIImage imageNamed:@"SchoolImageLandscape.png"]; 
    UIImageView *fView = [[UIImageView alloc] initWithImage:footerImage]; 
    [self.tableView setTableFooterView:fView]; 



} else if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
    NSLog(@"Portrait Mode"); 
    UIImage *footerImage = [UIImage imageNamed:@"SchoolImage.png"]; 
    UIImageView *fView = [[UIImageView alloc] initWithImage:footerImage]; 
    [self.tableView setTableFooterView:fView]; 
} 

不过,我遇到了一些麻烦确定如何使它用户没有看到这个变化,这意味着当它旋转时,你会看到较大的图像变成一个较小的图像,我不想要这个,

有没有人知道如何使过渡更加用户友好?我也尝试过设置imageView didRotateFromInterfaceOrientation的方法,并没有比这更好的了。

回答

0

好的,我不知道是否有更好的方法来做到这一点。

我做了什么:

willAnimateRotationToInterfaceOrientation方法,我做这个隐藏在tableFooterView:中,didRotateFromInterfaceOrientation方法然后

if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
    // hide the footer image so that the user doesn't see 
    // the image go from large image (landscape) to a smaller image 
    self.tableView.tableFooterView.hidden = YES; 

} 

,我决定

if (UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) { 
    NSLog(@"Going to Portrait Mode."); 

    UIImage *footerImage = [UIImage imageNamed:@"SchoolImage.png"]; 
    UIImageView *fView = [[UIImageView alloc] initWithImage:footerImage]; 

    [self.tableView setTableFooterView:fView]; 

    // unhide the footer 
    self.tableView.tableFooterView.hidden = NO; 

    // set the alpha to 0 so you can't see it immediately 
    fView.alpha = 0.0f; 

    // Fade in the image 
    [UIView transitionWithView:fView 
         duration:1.0f 
         options:0 
        animations:^{ 
         fView.alpha = 1.0f; 
        } completion:nil]; 

} 

本作过渡看起来更好。

希望这可以帮助别人。如果有人有更好的想法,请随时回答这个问题!

谢谢! =)

相关问题