【问题标题】:Present multiple Images in fullscreen全屏显示多个图像
【发布时间】:2015-03-21 04:30:19
【问题描述】:

我正在寻找 Apple 用于全屏显示多个图像的类的名称(类似于 iPad 上的 AppStore-App,当您点击任何应用程序的预览图像时。在视图的底部是一个栏,所有图片中的预览图片很少)。

如果这是一个公共类,它是如何调用的,它是否也适用于 iPhone?

【问题讨论】:

  • 不,您必须自己构建它。不过应该没那么难。
  • 我害怕这个答案...我想知道为什么苹果希望开发人员构建他们自己的图像全屏演示器,尽管它经常被需要。还是谢谢!
  • 因为他们很懒惰。 ;) 抱歉,但这是一个真正的问题吗?您之前是否曾在任何其他平台上构建过应用程序?在大多数平台上,您几乎必须自己构建所有东西。能在 iOS 开发中用到这么多东西,真是了不起。

标签: ios image fullscreen


【解决方案1】:

好的,所以我创建了自己的ImageFullScreenPresenter。 对于任何试图构建自己的ImageFullScreenPresenter 的人来说,重要的是使其成为UIViewController 的子类。

  PKImageFullScreenPresenter *pkImageFullScreen = [[[PKImageFullScreenPresenter alloc] initWithNibName:@"PKImageFullScreenPresenter" bundle:nil imageArray:myImageArray] autorelease];
        AppDelegate *appDel = (AppDelegate *)[UIApplication sharedApplication].delegate;
        UIViewController     *rootViewController;
        if (DEVICE_IS_IPAD) {
            //since the splitviewcontroller is the rootviewcontroller on ipad i set it as my temporary rootViewcontroller for ipad
            rootViewController  = appDel.splitViewController;
        }
        if (DEVICE_IS_IPHONE) {
            //on iphone i need the tabbarcontroller as temporary rootviewcontroller
            rootViewController  = appDel.tabBarController;
        }
        //set the alpha to zero, so it can fade in animated
        pkImageFullScreen.view.alpha    = 0;
        //save the temporary rootViewController, so I can set it back when dissmissing the ImageViewController
        pkImageFullScreen.superViewController       = rootViewController;

        //hide the status bar
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

        //setting black backgroundcolor
        [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor blackColor];

        //init the fullscreencontroller as rootview
        [[UIApplication sharedApplication].keyWindow setRootViewController:[[[UINavigationController alloc] initWithRootViewController:pkImageFullScreen] autorelease]];
//smooth fade animation
        [UIView animateWithDuration:.5f
                         animations:^(void){
                             pkImageFullScreen.view.alpha = 1;
                         }];

这样做,我可以在 iPhone 和 iPad 上显示ImageFullScreenPresenter,无论您使用的是基于窗口的应用程序、iPad 上的 splitViewController 还是其他任何东西。 关闭 ImageFullScreenPresenter 时,我将临时保存的 rootViewController 设置回动画:

- (void)closeView:(id)sender{
[UIView animateWithDuration:.5f
                     animations:^(void){
                         self.view.alpha = 0;
                     }completion:^(BOOL finished){
                         //show the statusbar again
                         [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
                         //setting the statusbarstyle
                         [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
                         //set the backgroundcolor for the window
                         [UIApplication sharedApplication].keyWindow.backgroundColor = GLOBAL_TINT_COLOR; //my custom color vor all GUI Objects
                         //set the temporary rootViewController back
                         [[UIApplication sharedApplication].keyWindow setRootViewController:superViewController];

                         //sometimes the navigationbar hides the statusbar, the following two lines help me out
                         [[UIApplication sharedApplication].keyWindow.rootViewController.navigationController setNavigationBarHidden:YES];
                         [[UIApplication sharedApplication].keyWindow.rootViewController.navigationController setNavigationBarHidden:NO];

                     }];

}

我不知道这是否是正确的方法,但它对我来说非常好。我不必担心任何轮换问题,就像我直接将其添加到 [UIApplication sharedApplication].keyWindow 时那样。

我希望这可以帮助其他尝试实现相同目标的人:)

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2013-10-04
    • 2019-05-07
    • 2013-02-14
    相关资源
    最近更新 更多