我的应用程序大多数页面都是Landscape,只有几页是Portrait。 Image显示了我的问题。对于纵向,键盘/日期选择器上方工具栏的位置不正确。 我将设备方向设置为纵向/横向左/右横向。在肖像页面我的代码
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
if ([NSObject isiPhone]) {
return UIInterfaceOrientationPortrait;
}
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
if ([NSObject isiPhone]) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotate{
return YES;
}
以下是我的工具栏代码:
UIToolbar *toolbar=[[UIToolbar alloc]init];
toolbar.barTintColor=[UIColor lightTextColor];
toolbar.frame=CGRectMake(0, 0, 320, 44);
UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"OK" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
toolbar.items = @[item2,item3];
self.babyBirthdayTextfield.inputAccessoryView=toolbar;
Web视图也出现此问题 my app Portrait view's structure
我已经解决了这个问题。该故事板的根控制器是模态窗口。改变了segue的种类。
答案 0 :(得分:0)
您无需手动管理工具栏的框架。只需使用textField的inputAccessoryView
,你就可以了:
UIToolbar* toolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelButtonTapped)],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped)],
nil];
[toolbar sizeToFit];
self.textField.inputAccessoryView = toolbar;
希望这有帮助。