问题描述:

I have a couple of UIViewController subclasses. One that displays a grid and another that is essentially the 'detail view' for the tile on the grid. The user taps a tile and the detail view expands from the grid to fill the screen.

I have managed to get the views to animate properly and can display the content of each view perfectly. My problem comes when the device is rotated. I have displayed the detail view as a subview of the gridview and so when I rotate the device, the grid view controller gets the rotation calls, not the detail view.

As this is a custom animation, I couldn't use the standard pop and push view controller methods. Is there an method that I have to call to make this view controller responsible for handling rotation until it is dismissed?

Thanks

网友答案:

If I understand correctly, you rotate your grid view controller and it responds, but the 'detail view' view controller doesn't change correctly?

If this is the case, there are two possible solutions I can think of (and currently use myself). One solution would be to register the 'detail view' for a notification. Whenever the grid view controller is rotated, send the notification and the 'detail view' should respond as you want it.

The other solution is just a simple check when the 'detail view' is loaded.

if (self.view.bounds.size.height < self.view.bounds.size.width) {
    // apply the code you wish to size it for landscape mode;
}

This, of course, would only work if the 'detail view' is not currently visible when the screen is rotated, so sending a notification may be a better choice to cover all possibilities.

网友答案:

You could set up a custom delegate in the grid view controller and register the detail view controller as that delegate after it is set up. In the grid view controller you then implement willRotateToInterfaceOrientation:duration: and didRotateFromInterfaceOrientation: which first call the corresponding methods in the delegate (the detail view controller) and then in super.

相关阅读:
Top