9

当应用程序第一次启动并为此使用时,我正在制作一个教程UIPageViewController。一切正常,但背景颜色UIPageViewController没有变得透明。一直是黑色的,如下图:

在此处输入图像描述 在此处输入图像描述

这是我添加的方式UIPageViewController(在标签栏控制器中)

.h 文件:

@interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource>

@property (strong, nonatomic) UIPageViewController *pageViewController;
@end

.m 文件(在 中viewDidLoad):

// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.view.backgroundColor = [UIColor clearColor];
TutorialViewController *startingViewController = [self viewControllerAtIndex:0];

                NSArray *viewControllers = @[startingViewController];

                [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self presentViewController:_pageViewController animated:YES completion:nil];

在我的 AppDelegate.m 中,我还设置UIPageControl了清除背景颜色:

UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
[pageControl setOpaque:NO];
self.window.backgroundColor = [UIColor clearColor];

我知道问题在于UIPageViewController的背景颜色。不能将控制器的背景设置为透明吗?

请帮忙!

谢谢。

4

2 回答 2

4

好的,我找到了解决方案:

  1. UIPageViewController.

UIView *view = [[UIView alloc] init]; view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_backgroung"]]; imageView1.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); [view addSubview:imageView1];

// Create page view controller
self.pageViewController = [self.storyboard 

instantiateViewControllerWithIdentifier:@"PageViewController"];
self.pageViewController.dataSource = self;
self.pageViewController.view.backgroundColor = [UIColor clearColor];                  
[self.pageViewController.view insertSubview:view atIndex:0];
  1. 对于您的 PageViewController viewControllers,选择带有图形或任何您想要的 PNG 图像,但要确保背景是透明的。
  2. 将你UIPageControl的背景设置为透明appDelegate.m

    UIPageControl *pageControl = [UIPageControl appearance]; pageControl.pageIndicatorTintColor = [UIColor whisperWhite]; pageControl.currentPageIndicatorTintColor = [UIColor whisperDarkGray]; pageControl.backgroundColor = [UIColor clearColor];

现在运行,您UIPageViewController将看起来像这样,(注意背景是静态的,只有文本在移动,因为我们从右向左滑动): 在此处输入图像描述

于 2015-11-18T12:59:21.833 回答
2

在呈现之前将这些设置为页面视图控制器

pageViewController.providesPresentationContextTransitionStyle = YES;
pageViewController.definesPresentationContext = YES;
[pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
于 2016-11-02T13:32:35.783 回答