如何在具有多个图像的 ScrollView 中放置一个 PageControl?
How to place a PageControl in ScrollView having multiple images?
我有一个滚动视图,其中包含一个视图,视图有五个图像,需要一个页面控件来显示导航状态,但页面控件隐藏在图像后面。我尝试了在互联网上搜索的所有内容,但无法罚款。
Implementation.h
@interface ScrollSecondViewController : UIViewController
{
IBOutlet UIView *scrContentSizeView;
IBOutlet UIScrollView * scrollView;
}
@property (nonatomic, weak) IBOutlet UIPageControl *pageControl;
@end
Implementation.m
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationItem setTitle:@"Scroll View"];
scrollView.contentSize = CGSizeMake(scrContentSizeView.frame.size.width, scrollView.frame.size.height);
scrollView.clipsToBounds = YES;
[scrollView setContentOffset:CGPointMake(750, 0) animated:YES];
// Do any additional setup after loading the view.
}
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_pageControl.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}
在 viewDidLoad 方法中,您应该添加以下代码作为添加所有子视图后调用的最后一个方法。
- (void)viewDidLoad {
[super viewDidLoad];
//do what u want
//this should be last
[self.view bringSubviewToFront:self.pageControl];
}
我有一个滚动视图,其中包含一个视图,视图有五个图像,需要一个页面控件来显示导航状态,但页面控件隐藏在图像后面。我尝试了在互联网上搜索的所有内容,但无法罚款。
Implementation.h
@interface ScrollSecondViewController : UIViewController
{
IBOutlet UIView *scrContentSizeView;
IBOutlet UIScrollView * scrollView;
}
@property (nonatomic, weak) IBOutlet UIPageControl *pageControl;
@end
Implementation.m
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationItem setTitle:@"Scroll View"];
scrollView.contentSize = CGSizeMake(scrContentSizeView.frame.size.width, scrollView.frame.size.height);
scrollView.clipsToBounds = YES;
[scrollView setContentOffset:CGPointMake(750, 0) animated:YES];
// Do any additional setup after loading the view.
}
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
_pageControl.currentPage = scrollView.contentOffset.x / scrollView.frame.size.width;
}
在 viewDidLoad 方法中,您应该添加以下代码作为添加所有子视图后调用的最后一个方法。
- (void)viewDidLoad {
[super viewDidLoad];
//do what u want
//this should be last
[self.view bringSubviewToFront:self.pageControl];
}