页面滚动时页面控制器不发生变化
Page controller not at change when page scroll
水平滚动可以正常工作,但 UIpagecontroller 不起作用意味着它不会改变,因为我滚动页面。我无法识别错误。请看下面的代码
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIScrollView *scroll;
@property (strong, nonatomic) IBOutlet UIPageControl *pgcnt;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *arry=[NSArray arrayWithObjects:@"a",@"b",@"c",@"e",@"f", nil];
for (int i=0; i<arry.count; i++) {
CGRect frame;
[self.scroll setPagingEnabled:YES];
_scroll.pagingEnabled=YES;
_scroll.bounces = YES;
[_scroll setShowsHorizontalScrollIndicator:NO];
[_scroll setShowsVerticalScrollIndicator:NO];
frame.origin.x=_scroll.frame.size.width*i;
frame.size=_scroll.frame.size;
UIView *view=[[UIView alloc]initWithFrame:frame];
view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[arry objectAtIndex:i]]];
[_scroll addSubview:view];
[self.pgcnt setCurrentPage:i];
// self.pgcnt.numberOfPages=arry.count;
}
_scroll.contentSize=CGSizeMake(_scroll.frame.size.width*arry.count,_scroll.frame.size.height);
// Do any additional setup after loading the view, typically from a nib.
}
如有任何建议或帮助,我们将不胜感激
我找到了解决方案,没有人帮助我,但没关系,我会帮助其他人。我没有添加委托方法,这就是为什么 Pagecontrol 点不起作用的原因。但现在工作正常。
pragma 标记 - UIScrollView 委托
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scroll.frame.size.width;
int page = floor((self.scroll.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pgcnt.currentPage = page;
}
谢谢
http://iosmadesimple.blogspot.in/2013/01/page-control-for-switching-between-views.html
水平滚动可以正常工作,但 UIpagecontroller 不起作用意味着它不会改变,因为我滚动页面。我无法识别错误。请看下面的代码
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) IBOutlet UIScrollView *scroll;
@property (strong, nonatomic) IBOutlet UIPageControl *pgcnt;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *arry=[NSArray arrayWithObjects:@"a",@"b",@"c",@"e",@"f", nil];
for (int i=0; i<arry.count; i++) {
CGRect frame;
[self.scroll setPagingEnabled:YES];
_scroll.pagingEnabled=YES;
_scroll.bounces = YES;
[_scroll setShowsHorizontalScrollIndicator:NO];
[_scroll setShowsVerticalScrollIndicator:NO];
frame.origin.x=_scroll.frame.size.width*i;
frame.size=_scroll.frame.size;
UIView *view=[[UIView alloc]initWithFrame:frame];
view.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[arry objectAtIndex:i]]];
[_scroll addSubview:view];
[self.pgcnt setCurrentPage:i];
// self.pgcnt.numberOfPages=arry.count;
}
_scroll.contentSize=CGSizeMake(_scroll.frame.size.width*arry.count,_scroll.frame.size.height);
// Do any additional setup after loading the view, typically from a nib.
}
如有任何建议或帮助,我们将不胜感激
我找到了解决方案,没有人帮助我,但没关系,我会帮助其他人。我没有添加委托方法,这就是为什么 Pagecontrol 点不起作用的原因。但现在工作正常。
pragma 标记 - UIScrollView 委托
- (void)scrollViewDidScroll:(UIScrollView *)sender
{
// Update the page when more than 50% of the previous/next page is visible
CGFloat pageWidth = self.scroll.frame.size.width;
int page = floor((self.scroll.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
self.pgcnt.currentPage = page;
}
谢谢 http://iosmadesimple.blogspot.in/2013/01/page-control-for-switching-between-views.html