I got a UIView containing an outlet to a UIScrollView.
I would like to detect when the view scroll.
This is my code:
// interface
@interface MyView : UIView <UIScrollViewDelegate>
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
-(void)setup;
// implementation
@implementation MyView
@synthesize scrollView;
-(void)setup {
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
scrollView.pagingEnabled = true;
[scrollView setContentSize:CGSizeMake(30, 160)];
scrollView.showsHorizontalScrollIndicator = false;
scrollView.bounces = false;
scrollView.scrollEnabled = true;
[self addSubview:scrollView];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@"Point: %@", NSStringFromCGPoint(scrollView.contentOffset));
}
What am I missing? Do I need to modify the storyboard to activate "scrollViewDidScroll"? Can I do this programmatically?
您需要在设置过程中设置scrollView的委托:
self.scrollView.delegate = self
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.