如何使UIPageViewController背景半透明?

我在网上搜索并找到类似这样的答案( 如何使用UIPageViewController半圆形的底部条形图? )但它并没有解决我的问题。

这是我的代码

// PageControl Layout UIPageControl *pageControl = [UIPageControl appearance]; pageControl.pageIndicatorTintColor = [UIColor lightGrayColor]; pageControl.currentPageIndicatorTintColor = [UIColor blackColor]; pageControl.backgroundColor = [UIColor clearColor]; // pageControl.frame = CGRectMake(5,5,305,400); pageControl = [UIPageControl appearanceWhenContainedIn:[self class], nil]; indexCurrentPage = 0; pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]; [pageController.view setFrame:[[UIScreen mainScreen] bounds]]; NSLog(@"page controller.fram is %@", [NSValue valueWithCGRect:[[pageController view] frame]]); pageController.dataSource = self; GuidedTourPage *initialViewController = [self viewControllerAtIndex:0]; [[self.pageController view] setFrame:[[initialViewController view] bounds]]; NSLog(@"bound is %@", [NSValue valueWithCGRect:[[initialViewController view] bounds]]); NSArray *viewControllers = [NSArray arrayWithObject:initialViewController]; [pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; [self addChildViewController:self.pageController]; [self.view addSubview:[pageController view]]; [pageController didMoveToParentViewController:self]; 

滚动function和其他一切工作正常。 除了有一部分图像丢失。 我做了self.window.backgroundColor = [UIColor whiteColor]; 在我的“AppDelegate.m”中,所以可以理解的是pageControl.backgroundColor = [UIColor clearColor]; 将使背景变白。

但我想要这样的东西( http://sofzh.miximages.com/ios/UIPageViewController-Tutorial-Screen.jpg ),其中pageControl具有透明背景。

我知道问题在于图层。 但我不知道如何解决它。 有没有办法让NSLog层层次结构来检查它? 或者是否有任何测试人员软件可以帮助我测试图层问题。 我不认为这将是一个非常难的问题,只要我能找到一种方法来调试像Firefox中的3D-Inspect元素函数这样的图层。

提前致谢

尝试这个:

 UIPageControl *pageControl = [UIPageControl appearance]; pageControl.backgroundColor = [UIColor clearColor]; 

你也可以玩Alpha:

 [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.7]; 

所以,声明将成为:

 pageControl.backgroundColor = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.7]; 

像这样的东西应该工作正常:

 [self.pageCont setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5]]; 

我已经validation了这个解决方案,请将UIPageViewController子类化并在实现中添加此方法。

 - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; for (UIView *view in self.view.subviews) { if ([view isKindOfClass:[NSClassFromString(@"_UIQueuingScrollView") class]]) { CGRect frame = view.frame; frame.size.height = view.superview.frame.size.height; view.frame = frame; [self.view sendSubviewToBack:view]; } } } 

这将解决问题。 谢谢