gpt4 book ai didi

ios - UIPageViewController 中的按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:59:55 25 4
gpt4 key购买 nike

我想将 UIButton 添加到我的 UIViewController。我在所有屏幕上都有一个 UIPageViewController。当我尝试添加此按钮时...屏幕上没有可见按钮。我做错了什么?

代码:

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

最佳答案

您的问题很可能是您首先将按钮添加为 subview ,然后创建了页面 Controller 并将其 View 添加到按钮“之上”。默认情况下,先添加的 subview 始终位于 稍后添加的 subview 之下。

如果您在该方法中将按钮创建代码移动到页面 Controller 代码之后,您的按钮应该出现在页面 Controller 的顶部。

关于ios - UIPageViewController 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25632260/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com