我从一个空的项目开始,并添加了一个视图控制器及其笔尖。在笔尖内部,有一个UIScrollView作为视图的孩子。在滚动视图中,我拥有多个资源,如文本框,标签和按钮。混淆为什么我的UISCrollView的框架为空
我在想让我的scrollview在键盘出现时上移的点。我查看了如何做到这一点的stackoverflow。我基本上复制了代码并试图理解它。但是,这个观点还没有上升。因此,一些调试语句的时间....
我的UIScrollView挂钩(IBOutlet)到RootViewController,并从那里访问。我尝试打印出我的scrollView(实例名称),我得到一个对象。但是,当我试图打印出scrollView.frame ....我得到空...有没有人有任何想法,为什么这是?
下面是一些代码片段与我的一些调试语句的
- (void) moveScrollView:(NSNotification *) notification up: (BOOL) upFlag{
NSDictionary * userInfo = [notification userInfo];
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
CGRect newFrame = scrollView.frame;
CGRect keyboardFrame = [self.view convertRect:keyboardEndFrame toView:nil];
NSLog(@"scrollView: %@", scrollView);
NSLog(@"frame: %@", scrollView.frame);
NSLog(@"Old Height: %@", scrollView.frame.size.height);
newFrame.size.height -= keyboardFrame.size.height * (upFlag ? 1 : -1);
NSLog(@"New Height: %@", newFrame.size.height);
scrollView.frame = newFrame;
[UIView commitAnimations];
}
- (void) keyboardShow:(NSNotification *) notification{
NSLog(@"Keyboard Show");
[self moveScrollView: notification up:YES];
}
它注册到keyboardWIllShow通知 – denniss