UIPageControl 中的问题
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(153,356,38,36) ];
pageControl.userInteractionEnabled =YES;
pageControl.numberOfPages = 2;
pageControl.currentPage = 1;
pageControl.enabled = TRUE;
[pageControl setHighlighted:YES];
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
}
- (IBAction) changePage:(id)sender
{
}
我正在以编程方式创建页面控件,并且我想在单击页面控件时显示新的视图控制器。我需要如何实现这个changePage方法?有人可以帮忙吗?
pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(153,356,38,36) ];
pageControl.userInteractionEnabled =YES;
pageControl.numberOfPages = 2;
pageControl.currentPage = 1;
pageControl.enabled = TRUE;
[pageControl setHighlighted:YES];
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:pageControl];
}
- (IBAction) changePage:(id)sender
{
}
I'm programmatically creating page control and i want to display new view controllers on click of page control. How i need to implement this changePage method? Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以显示两个视图,而不是显示两个不同的视图控制器。您可以保持选中第一个点并显示第一个视图,并在屏幕右侧显示下一个视图。当用户点击第二个点时,使 UIView 动画类似于 UINavigationController 中的推送。因此,您可以使用 UIView 动画进行推送和弹出。
如果要显示视图控制器,则页面控件需要在两个视图控制器中显示,以便用户可以从一个视图控制器切换到另一个视图控制器。在这种情况下,您需要将页面控件添加到主窗口中的视图中,以便其在任何地方都可见。
You can show two views instead of showing two different view controller. You can keep first dot selected and show first view and have next view out of screen, to its right. When user taps second dot, make UIView animation similar to pushing in UINavigationController. Thus, you do push and pop with UIView animation.
If you want to show view controllers, then the page control needs to be shown in both the view controller, so that user can switch from one to another. In such case, you need to have the page control in a view, added in the main window, so that its visible everywhere.
编写更改页面的方法的最简单方法如下:
编辑:如果您尝试通过单击点来简单地更改视图控制器,则需要设置页面,以便主视图在底部和上面的另一个 UIView(我们将称之为控制器视图)占据了大部分屏幕,但不覆盖页面控件。
您还需要在头文件中添加
PageOne *pageOneController;
和PageTwo *pageTwoController;
。这将有助于防止内存泄漏。因此,当您选择另一个页面时,您将调用
changePage
方法,这应该可以满足您的需要
The easiest way to program a method to change pages would be the following:
EDIT: if you are trying to simply change the view controller by clicking the dots, you will need to set your page up so that the main view has a UIPageControl at the bottom and another UIView (we will call this controllerView) above it taking up most of the screen, but not overlaying the page control.
You will also want
PageOne *pageOneController;
andPageTwo *pageTwoController;
in your header file. This will help prevent memory leaks.So when you select another page, you'll call your
changePage
methodThis should do the trick for you