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];
}

但是,我在确定如何在用户看不到更改的地方制作它时遇到了一些麻烦。这意味着当它旋转时,您会看到较大的图像变成较小的图像。我不想要这个。

有谁知道如何使过渡更加用户友好?我也尝试过设置 imageViewdidRotateFromInterfaceOrientation方法,但并没有更好。

4

1 回答 1

0

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

我做了什么:

在该willAnimateRotationToInterfaceOrientation方法中,我通过执行以下操作隐藏了 tableFooterView:

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;

}

然后在didRotateFromInterfaceOrientation方法中,我决定

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];

}

这使过渡看起来好多了。

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

谢谢!!!=)

于 2015-01-09T01:26:16.620 回答