Tôi đã một TutorialsViewController mà có một PageViewController thêm lập trình như:Child View Controller chuyển xuống
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// Create page view controller
self.pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsPageViewController"];
self.pageViewController.dataSource = self;
TutorialsContentViewController *startingViewController = [self viewControllerAtIndex:0];
NSArray *viewControllers = @[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
[self addChildViewController:self.pageViewController];
[self.view addSubview:self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
}
Và tôi thêm TutorialsContentViewController đến PageViewController bằng cách sử dụng phương pháp đại biểu:
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex;
if ((index == 0) || (index == NSNotFound)) {
return nil;
}
index--;
return [self viewControllerAtIndex:index];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSUInteger index = ((TutorialsContentViewController*) viewController).pageIndex;
if (index == NSNotFound) {
return nil;
}
index++;
if (index == [self.tutorialsArray count]) {
return nil;
}
return [self viewControllerAtIndex:index];
}
- (TutorialsContentViewController *)viewControllerAtIndex:(NSUInteger)index {
if (([self.tutorialsArray count] == 0) || (index >= [self.tutorialsArray count])) {
return nil;
}
// Create a new view controller and pass suitable data.
TutorialsContentViewController *tutorialsContentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"TutorialsContentViewController"];
tutorialsContentViewController.imageName = [self.tutorialsArray objectAtIndex:index];
tutorialsContentViewController.pageIndex = index;
return tutorialsContentViewController;
}
Bây giờ khi tôi chạy điều này trong giả lập, tôi có thể thấy mọi thứ hoạt động tốt, chỉ cần bộ điều khiển xem con tiếp theo xuất hiện ở trên thanh trạng thái và nó chuyển xuống khi tôi cuộn.
Tôi đã thử self.automaticallyAdjustsScrollViewInsets = false trong Trình điều khiển Chế độ xem dành cho cha mẹ nhưng chế độ xem con vẫn chuyển xuống. Bộ điều khiển xem con có một ImageView có các ràng buộc hàng đầu, theo sau, trên cùng, dưới cùng được đặt thành 0 ban đầu (điều này gây ra sự thay đổi).
Khi tôi căn giữa hình ảnh theo chiều ngang và chiều dọc và cho chiều cao cố định và chiều rộng, nó hoạt động tốt mặc dù. Nhưng tôi muốn hình ảnh hoàn toàn lấp đầy bộ điều khiển xem con.
Làm cách nào để giải quyết vấn đề này? Hãy giúp tôi.
Cảm ơn.