i want to get scrollView's contentOffset
and contentInset
during UIView animation like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
[self.window makeKeyAndVisible];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(100, 100, 120, 100)];
scrollView.backgroundColor = [UIColor grayColor];
scrollView.contentSize = scrollView.frame.size;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
label.textAlignment = NSTextAlignmentCenter;
label.text = @"hello world";
[scrollView addSubview:label];
UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:scrollView];
[scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
[scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew context:NULL];
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
scrollView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0);
scrollView.contentOffset = CGPointMake(0, -50);
} completion:nil];
self.window.rootViewController = vc;
return YES;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"contentOffset"]) {
NSLog(@"offset:%@", [change valueForKey:NSKeyValueChangeNewKey]);
}
if ([keyPath isEqualToString:@"contentInset"]) {
NSLog(@"inset:%@", [change valueForKey:NSKeyValueChangeNewKey]);
}
}
unfortunately there is no output while animating, am i miss something or KVO just doesn't work when doing UIView animating?