我遇到了一个问题,当我scrollViewDidScroll
在我的子类中调用该方法时UIScrollView
没有任何反应。这是我的代码:
AppDelegate.m
#import "ScrollView.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
CGRect screenRect = [[self window] bounds];
ScrollView *scrollView = [[ScrollView alloc] initWithFrame:screenRect];
[[self window] addSubview:scrollView];
[scrollView setContentSize:screenRect.size];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
滚动视图.m
#import "AppDelegate.h"
#import "ScrollView.h"
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSString *imageString = [NSString stringWithFormat:@"image"];
UIImage *image = [UIImage imageNamed:imageString];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[super addSubview:imageView];
}
return self;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"%f", scrollView.contentOffset.y);
}