@interface NewForm : UIVIEwController <uiscrollviewdelegate>{ BOol pageControlUsed;}@property (nonatomic,retain) IBOutlet UIScrollVIEw *scrollVIEw;@property (nonatomic,strong) IBOutlet UIPageControl *pageControl;@property (nonatomic,retain) NSMutableArray *vIEwControllers;- (IBAction)changePage:(ID)sender;@end
视图和scrollVIEw插座链接到file的所有者,以及滚动视图的委托. pageControl outlet和changePage链接到UIPageControl.
这是.m文件(实际上只是相关的方法):
@implementation STNewAccountTest@synthesize scrollVIEw,vIEwControllers,pageControl;- (voID)vIEwDIDLoad{ [super vIEwDIDLoad]; NSMutableArray *controllers = [[NSMutableArray alloc] init]; [controllers addobject:[[Page1 alloc] initWithNibname:@"Page1" bundle:nil]]; [controllers addobject:[[Page2 alloc] initWithNibname:@"Page2" bundle:nil]]; self.vIEwControllers = controllers; scrollVIEw.pagingEnabled = YES; scrollVIEw.contentSize = CGSizeMake(scrollVIEw.frame.size.wIDth * numberOfPages,scrollVIEw.frame.size.height); scrollVIEw.showsHorizontalScrollindicator = NO; scrollVIEw.showsverticalScrollindicator = NO; scrollVIEw.scrollsTotop = NO; scrollVIEw.delegate = self; self.pageControl.currentPage = 0; self.pageControl.numberOfPages = numberOfPages; [self loadScrollVIEwWithPage:0];}- (voID)loadScrollVIEwWithPage:(int)page{ if ((page < 0) || (page >= numberOfPages)) return; Page1 *controller1 = nil; Page2 *controller2 = nil; if (page == 0) { controller = [self.vIEwControllers objectAtIndex:page]; if (controller == nil) { controller = [[Page1 alloc] initWithNibname:@"Page1" bundle:nil]; [self.vIEwControllers replaceObjectAtIndex:page withObject:controller]; }}if (page == 1) { controller = [self.vIEwControllers objectAtIndex:page]; if (controller == nil) { controller = [[Page2 alloc] initWithNibname:@"Page2" bundle:nil]; [self.vIEwControllers replaceObjectAtIndex:page withObject:controller]; }}if (controller.vIEw.supervIEw == nil){ CGRect frame = self.scrollVIEw.frame; frame.origin.x = frame.size.wIDth * page; frame.origin.y = 0; controller.vIEw.frame = frame; [self.scrollVIEw addSubvIEw:controller.vIEw];}}- (voID)scrollVIEwDIDScroll:(UIScrollVIEw *)sender{ if (pageControlUsed) { return; } // Switch the indicator when more than 50% of the prevIoUs/next page is visible CGfloat pageWIDth = scrollVIEw.frame.size.wIDth; int page = floor((scrollVIEw.contentOffset.x - pageWIDth / 2) / pageWIDth) + 1; pageControl.currentPage = page; // load the visible page and the page on either sIDe of it (to avoID flashes when the user starts scrolling) [self loadScrollVIEwWithPage:page - 1]; [self loadScrollVIEwWithPage:page]; [self loadScrollVIEwWithPage:page + 1];}- (voID)scrollVIEwWillBeginDragging:(UIScrollVIEw *)scrollVIEw{ pageControlUsed = NO;}- (voID)scrollVIEwDIDEndDecelerating:(UIScrollVIEw *)scrollVIEw{ pageControlUsed = NO;}- (IBAction)changePage:(ID)sender{ int page = pageControl.currentPage; // load the visible page and the page on either sIDe of it (to avoID flashes when the user starts scrolling) [self loadScrollVIEwWithPage:page - 1]; [self loadScrollVIEwWithPage:page]; [self loadScrollVIEwWithPage:page + 1];// update the scroll vIEw to the appropriate page CGRect frame = scrollVIEw.frame; frame.origin.x = frame.size.wIDth * page; frame.origin.y = 0; [scrollVIEw scrollRectToVisible:frame animated:YES];// Set the boolean used when scrolls originate from the UIPageControl pageControlUsed = YES;}
当我运行应用程序时,我看到的是页面的视图占据了整个屏幕,我能够通过滚动视图的分页功能浏览页面,但页面控件及其点不会显示.我能错过什么?
谢谢!
解决方法 这里回答: https://stackoverflow.com/a/4245642/1455770“如果页面控件和容器的背景颜色相同(默认为白色),则页面控件将不可见.”
总结以上是内存溢出为你收集整理的ios – 与UIScrollView结合使用时UIPageControl不可见全部内容,希望文章能够帮你解决ios – 与UIScrollView结合使用时UIPageControl不可见所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)