您好,我正在尝试在用户滚动应用程序时触发一个功能。
这是我的代码
我定义了一个实现 UIScrollViewDelegate 的类 MyViewController
@interface CircleViewController : UIViewController <UIScrollViewDelegate> {
UIScrollView *scroll;
}
@property (retain, nonatomic) UIScrollView * scroll;
@end
然后,在 .m 中,我在 ViewDidLoad 中写道:
- (void)viewDidLoad {
[super viewDidLoad];
self.scroll = [[UIScrollView alloc] init];
scroll.delegate = self;
[scroll setBackgroundColor:[UIColor whiteColor]];
NSInteger nbView = 3;
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
for(int i = 0; i < nbView; i++) {
CGFloat xOrigin = i * self.view.frame.size.height;
UIView * vue = [[UIView alloc] initWithFrame:CGRectMake(0, xOrigin, self.view.frame.size.width, self.view.frame.size.height)];
vue.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:vue];
[vue release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * nbView);
[scroll setScrollEnabled:YES];
[self.view addSubview:scroll];
我定义了触发器:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"test");
}
当我运行应用程序时,我可以滚动,但 scrollViewDidScroll 永远不会被调用。