UIPageViewController和UIPageControl透明背景颜色 - iOS

问题描述:

我正在做一个教程,当应用程序第一次启动,并使用UIPageViewController。一切正常,但UIPageViewController的背景颜色不透明。它总是黑色的,如下图所示:UIPageViewController和UIPageControl透明背景颜色 - iOS

enter image description here enter image description here

这里是我如何加入UIPageViewController(在的TabBar控制器)

.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的背景色。是不是可以将控制器的背景设置为透明?

请帮忙!

谢谢。

好吧,我已经找到了解决办法:

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

  3. 现在运行和你UIPageViewController看起来就像这样,(注意背景的静态和只有文字是移动的,因为我们从右向左滑动): enter image description here

开始=>

将它们设置为页面视图控制器之前提交它

pageViewController.providesPresentationContextTransitionStyle = YES; 
pageViewController.definesPresentationContext = YES; 
[pageViewController setModalPresentationStyle:UIModalPresentationOverCurrentContext]; 
+0

这解决了我的问题,没有背景图片,我希望页面控制器背后的内容能够通过。 –