這是我的代碼如下:無法滾動?我的代碼有什麼問題?
-(void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
NSLog(@"------>> Reigster for keyboard events");
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
keyboardVisible = NO;
}
-(void) viewWillDisappear:(BOOL)animated {
NSLog(@"--->>Unregister keyboard event");
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)keyboardDidShow:(NSNotification *) notif{
NSLog(@"Received did show notifiation");
if (keyboardVisible) {
NSLog(@"Keyboard is already visible... ignoring notification");
return;
}
NSLog(@"Resizing smaller for keboard");
NSDictionary *info = [notif userInfo];
NSValue *aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
CGRect viewFrame = self.view.frame;
viewFrame.size.height -= keyboardSize.height;
scrollView.frame = viewFrame;
scrollView.contentSize = CGSizeMake(viewFrame.size.width, viewFrame.size.height);
//scrollView.contentSize = CGSizeMake(296, 217);
keyboardVisible = YES;
}
-(void) keyboardDidHide:(NSNotification *) notif {
NSLog(@"Received did Hide notification");
if (!keyboardVisible) {
NSLog(@"keyboard already hidden. Ignoring notification");
return;
}
NSLog(@"Resizing bigger with no keyboard");
NSDictionary *info = [notif userInfo];
NSValue *aValue = [info objectForKey:UIKeyboardFrameBeginUserInfoKey];
CGSize keyboardSize = [aValue CGRectValue].size;
CGRect viewFrame = self.view.frame;
viewFrame.size.height += keyboardSize.height;
//scrollView.contentSize = CGSizeMake(296, 417);
scrollView.contentSize = CGSizeMake(viewFrame.size.width, viewFrame.size.height);
keyboardVisible = NO;
}