我有一个带底部工具栏的DetailViewController。
此工具栏包含UIButtons和UITextField对象。
为了在编辑时看到这些UITextField,我使用以下例程:
- (void) returnMainViewToInitialposition:(NSNotification*)aNotification{
[self scrollViewForKeyboard:aNotification up:NO];
}
- (void) scrollViewForKeyboard:(NSNotification*)aNotification up:(BOOL) up{
if (_detailItem && ( self.addressTextField.editing || self.urlTextField.editing || self.titleTextField.editing )) {
NSDictionary* userInfo = [aNotification userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
CGRect keyboardFrame;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardFrame];
CGFloat _keyboardHeight = ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) ? keyboardFrame.size.height : keyboardFrame.size.width;
// Animate up or down
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:animationDuration];
[UIView setAnimationCurve:animationCurve];
[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + _keyboardHeight * (up?-1:1), self.view.frame.size.width, self.view.frame.size.height)];
[UIView commitAnimations];
NSLog(@"detailView bounds: %.0f, (%.0f + %.0f x %d), %3.0f, %3.0f", self.view.frame.origin.x, self.view.frame.origin.y + _keyboardHeight * (up?-1:1), _keyboardHeight, (up?-1:1), self.view.frame.size.width, self.view.frame.size.height);
}
}
+ (CGRect) convertRect:(CGRect)rect toView:(UIView *)view {
UIWindow *window = [view isKindOfClass:[UIWindow class]] ? (UIWindow *) view : [view window];
return [view convertRect:[window convertRect:rect fromWindow:nil] fromView:nil];
}
它可以工作,直到我在当前视图的顶部推送另一个视图,然后将其弹出。 然后我在编辑它时看不到我的UITextField。
以上是NSLog的说法:
推送(工作)之前:
detailView bounds: 0, (-704 + 352 x -1), 703, 768
弹出后(不):
detailView bounds: 0, (352 + 352 x 1), 703, 768
所以看来我的UIViewController在推/弹之间失去了self.view.frame.origin.y
......
在IB中,两个视图(detailView和pushView)的所有大小都设置为“推断”。以下两个视图的选项也相同:
那么,我的观点发生了什么? 谢谢你的帮助。
答案 0 :(得分:0)
与往常一样,它是关于如何添加观察者的:
它们不应该添加到viewDidLoad
方法中,而应添加到viewWillAppear
中。
现在已经修好了。