0

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

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

4

1 回答 1

0

好的,所以我创建了自己的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;
                         }];

这样做,ImageFullScreenPresenter无论您使用的是基于窗口的应用程序、iPad 上的 splitViewController 还是其他任何东西,我都可以在 iPhone 和 iPad 上展示它。关闭 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.

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

于 2013-02-20T09:49:48.093 回答