如何使 UIPageViewController 背景半透明? [英] How to make UIPageViewController background translucent?

查看:31
本文介绍了如何使 UIPageViewController 背景半透明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索并找到了类似的答案(如何使带有 UIPageViewController 点的底部栏变为半透明?)但它并没有解决我的问题.

I search on the web and found similar answers like this( How do I make the bottom bar with dots of a UIPageViewController translucent?) but it doesn't solve my problem.

这是我的代码

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

滚动功能和其他一切正常.除了有一部分图像丢失.我在AppDelegate.m"中做了 self.window.backgroundColor = [UIColor whiteColor]; 所以可以理解 pageControl.backgroundColor = [UIColor clearColor]; 将使背景为白色.

The scrolling function and everything else work fine. Except there is a portion of the image is missing. I did self.window.backgroundColor = [UIColor whiteColor]; in my "AppDelegate.m" so it's understandable that pageControl.backgroundColor = [UIColor clearColor]; will make the background to be white.

但我想要这样的东西(http://www.appcoda.com/wp-content/uploads/2013/06/UIPageViewController-Tutorial-Screen.jpg),其中 pageControl 具有透明背景.

But I want something like this (http://www.appcoda.com/wp-content/uploads/2013/06/UIPageViewController-Tutorial-Screen.jpg), in which the pageControl has a transparent background.

我知道问题出在图层上.但我不知道如何修复它.有没有办法 NSLog 层层次结构来检查它?或者有没有什么测试软件可以帮我测试图层问题.我不认为这会是一个非常困难的问题,只要我能找到一种方法来调试层,就像 Firefox 中的 3D-Inspect 元素功能.

I know the problem lies in the layer. But I don't know how to fix it. Is there a way to NSLog the layer hierarchy to check it? Or is there any tester software that can help me test the layer problem. I don't think this will be a very hard problem as long as I can find a way to debug the layers like the 3D-Inspect element function in Firefox.

提前致谢

推荐答案

试试这个:

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

你也可以和 Alpha 一起玩:

You can play with Alpha too:

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

这篇关于如何使 UIPageViewController 背景半透明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆