问题标签 [viewwilltransitiontosize]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
7 回答
4290 浏览

ios - Nested UICollectionViews, AutoLayout and rotation in iOS 8

I started to use AutoLayout for a large project and was positively surprised about it. However, now I have to adjust the project to accommodate for rotation and size classes, and I have big troubles getting the views to behave correctly.

The base problem is that I have UICollectionViews with cells that again contain UICollectionViews. When the device is rotated, the base collection view adapts it's cells right, but all cells of the nested collection views are not adjusted to the new size automatically.

After investigation it comes down to:

  • When viewWillTransitionToSize is called, the base collection view is not rotated yet (as expected)
  • Sometime after that viewDidLayoutSubviews is called, the base collection view now has the rotated size - but unfortunately its cells not yet - they still have the width as BEFORE the rotation
  • Even in the coordinator animateAlongsideTransition ... completion:{} block in viewWillTransitionToSize the cells do not have their new width yet.

The above means that there is no place where I could possible tell the cells of the nested collection views to change their size, as I don't know the new widths yet; and the autolayout system does not automatically adjust them.

Does anyone else have the same problem or know a solution?

0 投票
0 回答
463 浏览

objective-c - viewdidload 中的帧大小不正确,viewdidappear

使用iOS8。视图的帧大小在和UIViewController's中不正确。我可以从中获取正确的帧大小并执行视图更新(我需要使布局无效),但是处理旋转变得毫无意义,并且这两种方法将其淘汰。viewDidLoadviewDidAppearviewDidLayoutSubviewsviewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

理想情况下willTransitionToSize会被调用而不是didLayoutSubviews,但不能同时调用,因为我不知道我是否真的需要使布局无效并执行无意义的计算、布局等。

我想避免使用与旋转和帧大小更改有关的各种魔术标志。

在发生任何这种情况之前,有没有办法获得视图控制器视图的“真实”大小?

编辑

这是一些示例代码:

0 投票
2 回答
2964 浏览

ios - iOS8 - 在 UINavigationController 上推送 UIViewController 并旋转设备后,以前的视图控制器中的大小错误

我有UINavigationController一个根UIViewController(“根”)。

根视图控制器推送另一个UIViewController“孩子”。当“孩子”UIViewController出现在屏幕上时,我旋转设备并期望“根”视图控制器相应地调整大小,但这并没有发生。在根视图控制器中放置断点后:

我看到大小错误,并且根视图控制器没有正确调整以适应更改。

有没有人经历过这种行为?

代码是这样的:

在此处输入图像描述

这是旋转设备后大小的 NSLog 的打印屏幕 - 这是来自模拟器,但在设备上的行为是相同的。

在此处输入图像描述

0 投票
2 回答
2261 浏览

ios - ViewWillTransitonToSize 旋转动画

我正在尝试替换 UIcollectionView 上的默认 iOS 设备旋转动画。我在 transitionCoordinator 上使用 viewWillTransitionToSize 和 targetTransform() 来防止默认视图旋转,然后使用变换将每个 visibleCell 旋转到正确的方向。它工作正常,除了:

  1. 可见矩形直接外部边界上的单元格没有旋转。
  2. 我的日志显示 collectionView.visibleCells() 数组给了我它应该做的:可见单元格,但我发现如果我让视图以默认动画旋转,则 visibleCells 数组给我可见单元格加上单元格在附近。
  3. 我一直在尝试访问这些“社区”单元,以便可以旋转它们,但我所有的尝试都失败了。

这是我的 ViewWillTransitionTosize 实现:

这是一个快速的 gif。说明问题: http: //www.blessinglopes.com/Info

任何帮助将不胜感激!谢谢!

0 投票
1 回答
270 浏览

objective-c - 使用 Objective C 在 iOS8 中分离横向和纵向视图

我使用下面的代码在 iOS7 中有单独的横向和纵向视图:

我知道我应该在 iOS8 中使用 viewWillTransitionToSize 方法,但我不知道如何在该方法中获取这些不同的视图。提前感谢您的帮助。

0 投票
1 回答
3623 浏览

ios - viewWillTransitionToSize 和错误的 navigationBar 和 statusBarFrame 高度

我正在尝试获取 GLKViewController 子类的可见绘图区域。在 iOS 7 中,我会确定方向,然后相应地调整 [UIScreen mainScreen].bounds.size。然后我会减去 navigationBar 和 statusBarFrame 的高度,瞧!- 我的绘图区域的实际大小。

现在我正在尝试使用 viewWillTransitionToSize 更新 iOS 8,但是当我旋转设备时(我打开了 UIInterfaceOrientationMaskAll),传递的大小是错误的。事实上,视图的宽度是正确的,但高度不正确(这涉及到导航栏和状态栏的高度)。

我已经看到了一些关于 SO 的问题,但没有任何实际涉及这个问题的问题,至少没有任何对我有帮助的问题。

在我看来,这似乎没有做任何有趣的事情,如果我错了,请纠正我:

转换为横向的输出:

从 viewWillTransitionToSize 传递的高度似乎是:

然后下一个旋转到纵向:

从 viewWillTransitionToSize 传递的高度似乎是:

32恰好是横向模式下导航栏的高度(如果这意味着什么)。

所以我的问题是:viewWillTransitionToSize 是如何得到这个大小的?它如何考虑根据方向改变大小或消失的额外条?最重要的是,为什么要使用这些不正确的高度?

0 投票
0 回答
109 浏览

ios - iOS:如何允许一个视图的动画并禁止另一个视图的动画

我有 AVCaptureSession 视图和其他一些 UI 元素的视图。我需要手动处理设备旋转并设置此 UI 元素的位置且无需动画。我设置UIView setAnimationsEnabled:NOviewWillTransitionToSize防止动画,但它会影响所有动画,因此也影响没有动画的工作setVideoOrientation方法。AVCaptureVideoPreviewLayer我该如何解决这个问题?

0 投票
1 回答
795 浏览

ios - Autoresizingmask、viewWillTransitionToSize 和旋转

我有parentViewController,它包含customViewController带有autoresizing掩码的容器(灵活的宽度和高度)。容器的宽度约为parentViewController视图的 80%。当我旋转设备viewWillTransitionToSize:withTransitionCoordinator:被调用但尺寸“错误”时。我得到parentsViewController视图大小。

这是一部分customViewController

当我看到至少两种不同的尺寸时,为什么只调用一次?如果自动调整蒙版可以为我做,我不想计算视图大小。

如何让先应用自动调整大小的蒙版,然后在应用后获取大小?

viewWillTransitionToSize使用自动调整大小的蒙版时正确的使用方法是什么?

0 投票
3 回答
3816 浏览

ios - 为什么在 displayModeButtonItem 触发 splitViewController 崩溃时没有调用 viewWillTransitionToSize...?

我有一个 UISplitViewController,其辅助(详细)VC 是 UICollectionViewController。我希望集合的单元格根据集合视图的大小和方面的变化来调整大小。我通过覆盖 UIContentContainer 协议方法来触发这种调整大小:

当设备旋转时,这被调用并按照我想要的方式工作;但是当按下 splitViewController?.displayModeButtonItem() 提供的按钮以显示或折叠主(主)视图控制器时,不会调用此方法。由于该折叠必然会更改辅助(详细)视图的大小,因此我会认为应该在触发时调用 viewWillTransitionToSize... 方法。

所以,两个问题:

1)实际上是否应该在按下 displayModeButtonItem 时调用 viewWillTransitionToSize... 方法?如果是这样,我似乎发现了一个错误。

2)如果我所看到的实际上是正确的行为,任何人都可以建议一种方法让我的辅助(详细)控制器“知道”何时按下 displayModeButtonItem,或者当它的大小因该按钮而发生变化时被压?

谢谢!

卡尔

0 投票
1 回答
608 浏览

ios - viewWillTransitionToSize causes non-rotating view controller to resize and reposition

A lot of people have discussed techniques for mimicking the native iOS camera app (where the UI elements pivot in-place as the device rotates). I actually asked a question about it before here. Most people have you lock the orientation of the UI, but then force a transformation on just the elements that you want to pivot. This works, but the elements don't pivot with the smooth animations you see in the native iOS app and it leads some issues. Specifically, part of my interface allows users to share without leaving this interface, but when the sharing view gets rotated, it comes out off-center. So I wanted to find a different way to do this.

I found a link to Apple's AVCam sample, which got me off to a start here. I'm new to this stuff, but I managed to convert it from Obj-C to Swift already. Below is the key element of what I'm currently using:

I then have separate view controllers for icons that do the same transformation in the opposite direction. The icons actually pivot in place properly now (with smooth animations and everything) and the camera preview stays properly oriented.

The problem is, the non-rotating view gets resized and everything gets misplaced when I rotate the device from portrait to landscape or vice-versa. How do I fix that?