UIPageViewController中的按钮
问题描述:
我想添加UIButton到我的UIViewController。我在所有屏幕上都有一个UIPageViewController。当我试图添加此按钮时......屏幕上没有按钮可见。我做错了什么?UIPageViewController中的按钮
CODE:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(setButtonVisibleClose:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Zamknij widok" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.backgroundColor = [UIColor whiteColor];
[self.view addSubview: button];
self.pageController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageController.dataSource = self;
[[self.pageController view] setFrame:[[self view] bounds]];
BasicViewViewController *initialViewController = [self viewControllerAtIndex:0];
[initialViewController setImageViewToDisplay];
NSArray *viewControllers = [NSArray arrayWithObject:initialViewController];
[self.pageController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];
答
你的问题很可能是你添加的按钮作为一个子视图第一,然后创建页面控制器并加入它的观点“之上”的按钮。首先添加的子视图始终默认放置在之下,后面添加子视图。
如果您将按钮创建代码移动到该方法中的页面控制器代码之后,您的按钮应该出现在页面控制器的顶部。
尝试添加按钮的最后一个,即在[self.pageController didMoveToParent ...] ..我的猜测是,它由您添加的子视图覆盖。 – Mike 2014-09-02 21:45:13
你是对的。它被覆盖。现在它工作正常。 – DKM 2014-09-02 22:05:42
好吧,我会补充说,作为一个'官方'的答案,以防万一以后有人来。 :) – Mike 2014-09-02 22:06:36