[英]Objective-C - Scrollview Events
I found some answer that quite solve my questions, but seems that I'm missing some steps. 我找到了一些可以完全解决我问题的答案,但是似乎我缺少一些步骤。 I'm just trying to intercept the "ViewDidBlablabla" events of a ScrollView, so I created a custom UIScrollView class.
我只是想拦截ScrollView的“ ViewDidBlablabla”事件,所以我创建了一个自定义UIScrollView类。
#import "MyScrollView.h"
@implementation MyScrollView
- (id)initWithFrame:(CGRect)frame{
NSLog(@"initWithFrame");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(void)scrollViewWillBeginDragging:(UIScrollView*)scrollView{
NSLog(@"scrollViewWillBeginDragging");
//scrollView.contentOffset
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView{
NSLog(@"scrollViewDidScroll");
}
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
NSLog(@"scrollViewDidEndScrollingAnimation");
}
@end
#import <UIKit/UIKit.h>
@interface MyScrollView : UIScrollView <UIScrollViewDelegate>
@end
When I alloc my custom Scroll View I do get the console message "initWithFrame", but there's no way to get to the other events. 分配自定义滚动视图时,我确实收到了控制台消息“ initWithFrame”,但无法获取其他事件。 What am I missing?
我想念什么?
If you need some other pieces of code feel free to ask, but since I get to my custom "initWithFrame" method, I suppose that the error should be here. 如果您需要其他一些代码,请随时询问,但是由于我使用了自定义的“ initWithFrame”方法,因此我认为错误应该在这里。
Try setting your view as the delegate of itself: 尝试将视图设置为自身的委托:
if (self) {
// Initialization code
self.delegate = self;
}
Technically, you do not need to inherit UIScrollView
to respond to scrolling events: it is sufficient to set the delegate
to an implementation of <UIScrollViewDelegate>
. 从技术上讲,您无需继承
UIScrollView
即可响应滚动事件:将delegate
设置为<UIScrollViewDelegate>
的实现就足够了。
Also, the scrollViewDidEndScrollingAnimation:
method has been gone for about two years , so it is not going to be called on modern iOS installations. 另外,
scrollViewDidEndScrollingAnimation:
方法已经消失了大约两年了 ,因此在现代的iOS安装中不会被调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.