-->

ModalViewController doesn't display during ani

2020-07-25 10:57发布

问题:

My application has a paged scrollview. Each page of the scrollview has an instance of a view controller (buttonViewController) that shows a grid of buttons. If the user clicks on one of the buttons, buttonViewController launches a detailViewController modally, with animation set to YES.

If I'm viewing the first page (furthest left) or the scroll view, everything work's correctly. However, if I am scrolled to any of the other pages, the modal view animation (sliding up from the bottom in this case) doesn't appear. Instead, the whole view goes black for the same length of time that the animation would run for, and then the modal view controller appears fully displayed. The same thing happens when dismissing the modal view controller.

The code is completely standard. In my buttonViewController I call:

[self presentModalViewController:detailController animated:YES];

The same code runs no matter which page I'm looking at (though on different instances of buttonViewController of course.)

How would I start debugging this?

回答1:

This might have to do with the frame of the detailController...When you are in a UIScrollView, the first page is between 0 and 320, however when you scroll that offset increments, so (assuming you have full screen pages) the next view will be 320 and 640, the next one will be in 640 and (640+320), and so on and so forth. So when you are setting up your detailController with frame CGRectMake(0,0,320,460), when you are in the first page, the animation will look fine, but when you are in any other page the animation will take place at (0,0) and then im guessing the viewcontroller sees this is not the active screen a nd moves the modal view controller to where the active screen is. If you initialize your frame like this CGRectMake(320*pageNumber,0,320,460) I think youll have the d esired behavior you are looking for. Let me know if this works im curious myself.



回答2:

You need to insert a UIView (or any kind of view e.g. UIScrollView) under the view you are trying to animate, you will get the animation work correctly. I guess this is because you are providing a view that the animation is based on.