- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 3 个 View 的 viewController:topView、tableView 和 textView。
我希望他们这样布局:
在纵向模式下 -
|---------------|
| topView |
|---------------|
| |
| |
| tableView |
| |
| |
|---------------|
| textView |
|---------------|
横向模式:
|--------------------------|
| topView |
|--------------------------|
| |
| tableView |
|--------------------------|
| textView |
|--------------------------|
当键盘启动时:
|---------------|
| |
| tableView |
| |
|---------------|
| textView |
|---------------|
| |
| keyboard |
| |
|---------------|
|--------------------------|
| tableView |
|--------------------------|
| textView |
|--------------------------|
| |
| keyboard |
|--------------------------|
(如您所见,当键盘打开时顶 View 消失了)
执行此操作的代码是:
- (void)loadView
{
[super loadView];
// load top view
_topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, TOP_VIEW_HEIGHT)];
_topView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin;
_topView.backgroundColor = [UIColor redColor];
[self.view addSubview:_topView];
// load table view (at the middle)
CGRect tableFrame = CGRectMake(0, TOP_VIEW_HEIGHT, self.view.bounds.size.width, self.view.bounds.size.height - TOP_VIEW_HEIGHT - TEXT_VIEW_HEIGHT);
_tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
// load text view (at the bottom)
CGRect textViewFrame = CGRectMake(0, tableFrame.size.height + TOP_VIEW_HEIGHT, self.view.bounds.size.width, TEXT_VIEW_HEIGHT);
_textView = [[UITextView alloc] initWithFrame:textViewFrame];
_textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
_textView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:_textView];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect textViewFrame = self.textView.frame;
textViewFrame.origin.y -= kbSize.height;
CGRect topViewFrame = self.topView.frame;
topViewFrame.origin.y -= topViewFrame.size.height;
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y -= topViewFrame.size.height;
tableFrame.size.height -= (kbSize.height - topViewFrame.size.height);
[UIView animateWithDuration:animationDuration delay:0.0 options:animationCurve animations:^{
self.textView.frame = textViewFrame;
self.tableView.frame = tableFrame;
self.topView.frame = topViewFrame;
}completion:^(BOOL finished) {
}];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSDictionary *userInfo = [notification userInfo];
// Get animation info from userInfo
NSTimeInterval animationDuration;
UIViewAnimationCurve animationCurve;
[[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] getValue:&animationCurve];
[[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] getValue:&animationDuration];
CGSize kbSize = [[userInfo objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
CGRect textViewFrame = self.textView.frame;
textViewFrame.origin.y += kbSize.height;
CGRect topViewFrame = self.topView.frame;
topViewFrame.origin.y += topViewFrame.size.height;
CGRect tableFrame = self.tableView.frame;
tableFrame.origin.y += topViewFrame.size.height;
tableFrame.size.height += kbSize.height - topViewFrame.size.height;
[UIView animateWithDuration:animationDuration delay:0.0 options:animationCurve animations:^{
self.textView.frame = textViewFrame;
self.tableView.frame = tableFrame;
self.topView.frame = topViewFrame;
}completion:^(BOOL finished) {
//
}];
}
我想要的大部分都运行良好,问题是当键盘以横向模式显示时,然后就会出错..
请注意 View 的 autoresizingMask
属性,因为我不确定我当前是否设置了它。
最佳答案
对于自动旋转,尝试将顶 View 的 mask 设置为灵活宽度,中间的 mask 设置为灵活宽度和灵活高度,以及 TextView 、灵活宽度和上边距。我怀疑这是否会顺利进行,但值得一试。您可以覆盖 View Controller 上的 willAnimateRotationToInterfaceOrientation:duration:
以进行自定义工作。我很确定基本的自动旋转蒙版无法处理这种布局,但我很乐意被证明是错误的。
同时检查 loadView
中的方向,如下所示:
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
// do one layout
} else {
// do another layout
}
我也在我的应用程序中做非常自定义的旋转工作(从头开始想想自定义 Split View Controller ——糟糕),我正在使用 willAutorotate
和 UIInterfaceOrientationIsLandscape
.
这可能不适用于您,因为您对问题的措辞方式:我不确定问题是否出在您打开键盘,然后旋转到横向(在这种情况下,此答案可能会有所帮助);或者当您横向打开键盘时是否遇到问题(在这种情况下,此答案可能不太适合您)。
关于iphone - objective-c - 横向 UIView 自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922210/
即使我的设备旋转(纵向->横向->纵向),我也需要始终以横向模式录制视频。 取角度很简单,我用的是hyroscope。我的问题是总是横向录制视频。需要任何建议。 我正在使用 AVCaptureSess
我正在 iPad(1,2) 以及 Samsung Tab 2 上测试我的网络应用程序。我有不同的 CSS(外部)集可应用于 iPad 上的横向/纵向模式和选项卡 2 上的横向/纵向模式。 但我无法为
我正在将Snappy Bundle和Symfony 2.1一起使用。 我有一些问题未在此捆绑包的文档中找到: 如何设置方向? 有没有显示页码的方法? 这是我的捆绑包的config.yml: knp_s
我一直在寻找这个问题的答案,但找不到任何答案。显然,iPhone SDK 3.0 使得 UIImagePickerController 可以以横向模式显示成为可能 - 但我没有找到任何允许这样做的方法
我有 1 个 Storyboard,我在 Swift 3 中的 Xcode 8 上使用带有大小类的自动布局。 我有这个当前的肖像 View : 目前,这是 1 个带有标签的垂直堆栈 View 。 在横
我正为这个而焦头烂额。基本上,我需要我的菜单根据菜单的内容水平放置一个容器。所以,我知道 table 和 table-cell 属性可以做到这一点。但是,当我将其与 Superfish Menu 结合
我努力做到这一点: 但我无法正确获取第三列和翻转的标题。 我现在是这样的: 最佳答案 该解决方案适用于 IE9、Chrome、Firefox、Safari 和 Opera,不需要 JavaScrip
我想要一个水平方向的 WPF DataGrid,有人知道解决方案吗? 最佳答案 我之前已经这样做了,因为我们希望能够对 DataGrid 和 PropertyGrid 使用相同的控件。很多事情都必须改
我正在开发一个适用于智能手机的网站版本,在处理智能手机横向方向的媒体查询时遇到了一个小问题。对于纵向,我正在使用以下媒体查询并且它工作得很好: @media only screen and (max-
如何让“AVCaptureVideoPreviewLayer”在横向方向上正确显示?它在纵向模式下工作正常但不旋转,并且当父 View Controller 处于横向模式时显示旋转的相机捕获。 最佳答
这个问题在这里已经有了答案: Force "portrait" orientation mode (12 个回答) 关闭2年前。 我的第一款 Android 游戏即将完成,但我遇到了一个非常简单的问题
我的数据在其中一个字段中具有嵌套映射。例如,数据位于名为“customers”的表中,如下所示: 姓名:比尔·琼斯 地址:{"billing":{"street":"123 Main", "city"
我正在横向模式下运行应用程序。我需要注意什么才能使拍摄的屏幕截图也处于横向模式。 我在 iPhone 应用程序中使用以下代码,底部有标签栏并拍摄屏幕截图,但它始终仅处于纵向模式。为什么? UIWind
谁能举例说明如何将单点触控应用程序的 View 从纵向旋转为横向,反之亦然? 最佳答案 如果您在 Interface Builder 中设置 ui 元素的几何形状,请确保在 Size Inspecto
我正在使用简单的 MPMoviePlayerController。在纵向模式下,它嵌入到我的布局中。当我旋转我的设备时,我希望它全屏显示。在全屏模式下,有一个完成按钮,但它唯一的作用就是暂停视频。当点
我正在尝试读取 JSON 模式,但似乎无法弄清楚如何将所有先前对象等输出到层次结构中。 这是JSON响应方案 { "Shopping": { "Orders": { "OrderInfo": {
我想在我的布局中包含一个 SlidingDrawer,但我会将它放在布局的侧面。所以开口是从左到右,而不是从下往上。这怎么办? 最佳答案 this link可能会帮助您创建水平滑动抽屉。如果您正在使用
就在我以为我已经解决了所有问题时..我遇到了这个问题。 场景。 我有一个简单的 tableView。并在导航项的 titleView 中带有搜索栏。 SearchBar 通过 View Control
我有一个带有 MGSplitView 的应用程序,其中包含表格 View 和 UIWebView,该应用程序固定为横向。 Web View 有一个附加到 Web View 的 UITapGesture
我有一部 iPhone,我正在添加横向支持。之前只是肖像。 当键盘显示时,我无法将文本字段移开。 我使用的解决方案与记录在案的 Apple 解决方案非常相似 here . 该解决方案在纵向模式下工作正
我是一名优秀的程序员,十分优秀!