8

Tôi đang tạo một hướng dẫn khi ứng dụng khởi chạy lần đầu tiên và sử dụng UIPageViewController cho điều đó. Mọi thứ đều hoạt động tốt nhưng màu nền của UIPageViewController không rõ ràng. Đó là luôn có màu đen, như hình dưới đây:Màu nền trong suốt UIPageViewController và UIPageControl - iOS

enter image description here enter image description here

Đây là cách tôi đang thêm UIPageViewController (trong một bộ điều khiển thanh tabbar)

hồ sơ .h:

@interface CHMainTabViewController : UITabBarController <UIPageViewControllerDataSource> 

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

.m tệp (trong 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]; 

trong AppDelegate.m của tôi, tôi cũng đã thiết 'màu nền s để xóa:

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

Tôi biết rằng vấn đề là với UIPageViewController' UIPageControl màu nền s. Có thể đặt nền của Trình điều khiển thành minh bạch không?

Vui lòng trợ giúp!

Cảm ơn.

Trả lời

3

Được rồi tôi đã tìm thấy các giải pháp:

  1. Đặt một hình ảnh nền trên 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. Đối PageViewController bạn viewControllers, chọn một hình ảnh PNG với đồ họa hoặc bất cứ điều gì bạn muốn, nhưng chắc chắn rằng nền trong suốt.
  2. Đặt UIPageControl của bạn 's nền trong suốt trong appDelegate.m

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

Bây giờ chạy và UIPageViewController của bạn sẽ trông như thế này, (chú ý nền tĩnh và chỉ có văn bản đang chuyển động, như chúng ta vuốt từ phải sang trái): enter image description here

1

Đặt chúng vào bộ điều khiển chế độ xem trang trước khi trình bày

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

Điều này đã khắc phục sự cố của tôi không có hình nền và tôi muốn nội dung phía sau bộ điều khiển trang đi qua. –

Các vấn đề liên quan