2

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?

Nathaniel Martin
  • 2,082
  • 1
  • 14
  • 11

2 Answers2

2

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.

Daniel
  • 22,363
  • 9
  • 64
  • 71
  • Didn't seem to work. I added in: detailController.view.frame = CGRectMake(320*self.page,0,320,460); ... [self presentModalViewController:detailController animated:YES]; But it didn't seem to make a difference. As a note, I wasn't using initWithFrame before, I was using initWithNibName. That was a good idea though, thanks. – Nathaniel Martin Jul 28 '09 at 17:42
  • are you sure self.page is being updated correctly (ie its not always 0?) – Daniel Jul 28 '09 at 17:47
  • Yeah, it's definitely updating correctly, I just checked it with an NSLog() statement. Actually, setting the frame as I listed above actually makes the detailcontroller's imageview not display correctly. – Nathaniel Martin Jul 28 '09 at 17:55
  • One last suggestion, try using UIScrollView property contentOffset to dynamically determine the bounds of your frame – Daniel Jul 28 '09 at 17:59
  • Nope that doesn't either. Thanks though. This raises a question for me though. When you init a viewController with initWithNibNamed, where does it get its frame from? – Nathaniel Martin Jul 28 '09 at 18:08
  • It comes from the nib, you can specify the frame there – Daniel Jul 28 '09 at 18:11
  • Frame is relative to the superview though, right? In this case then, shouldn't the superview be the buttonView? In which case, the frame should still be at 0,0. Since the buttonViewController is adding the modal view controller, they should both be embedded in the scrollview, so the view hierarchy should be scrollView->buttonView->detailView. Correct? In which case, the only view that should have a frame that's not at 0,0 should be buttonView, which should be at contentOffset. (which is how the code is now.) – Nathaniel Martin Jul 28 '09 at 18:23
  • 1
    Im not too sure of how your stuff is structured, but I would say the scrollViews ViewController should be pushing the modal view – Daniel Jul 28 '09 at 19:08
  • That works, and fixes the animation. I don't really like it, because I feel that the buttonController should be launching and dismissing its own modal view controllers, not telling the scrollView to. But I guess it works. Unfortunately, now that's messed up my scrollView, and when I return from the modal view controller, horizontal and vertical scrolling is occuring, as well as paging. oh well. – Nathaniel Martin Jul 28 '09 at 20:24
  • Managed to get both this, and my other question fixed! I was mismatching the sizes of the view controllers. So the combination of that, and launching from the wrong view controller, was screwing me up. Thanks! – Nathaniel Martin Jul 28 '09 at 20:56
  • The reason it is not working with the buttons controller is that it knows nothing of the scroll view and therefore does not know to show the animation with the offset... what do you mean horizontal and vertical scrolling is occuring? – Daniel Jul 28 '09 at 20:57
  • I meant that when I returned from the modal view controller, if I dragged on the scrollview, instead of just jumping from one page to another, it actually scrolled up, down, left, right, etc. Turns out, because some of my viewcontrollers were set to 480 pixels high, and some were 460, it was re-laying out the scrollview when I returned from the modal view controller, and that made it scroll. Once I fixed the heights, everything is working great now. Thanks for your help! – Nathaniel Martin Jul 28 '09 at 21:04
0

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.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Khiet
  • 872
  • 1
  • 10
  • 15