views:

1023

answers:

4

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?

+2  A: 

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
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
are you sure self.page is being updated correctly (ie its not always 0?)
Daniel
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
One last suggestion, try using UIScrollView property contentOffset to dynamically determine the bounds of your frame
Daniel
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
It comes from the nib, you can specify the frame there
Daniel
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
Im not too sure of how your stuff is structured, but I would say the scrollViews ViewController should be pushing the modal view
Daniel
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
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
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
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
A: 

Nathanniel,

Did you ever figure out a solution to this problem?

I'm having the exact same issue except it was working with OS 2.2.1 when my app was tested against. The behavior only manifests on 3.x even if I have built for 2.2.1.

Simulator w/ 3.0 exposes the problem but I haven't been able to test on a 3.0 device yet.

What's really annoying is that it was working fine with 2.2.1. Sighs...

I even tried the 3.0 specific transition style but of course no luck:

viewController.modalViewController = UIModalTransitionStyleCoverVertical;

Any insights much appreciated.

Franky
A: 

Hi guys! I have exactly the same problem and changing view.frame.origin.x or y to any reasonably value doesn't solve the problem. I'm stuck and appreciate any help! I hope I can figure out and post the solution :)

I found a solution :)

SOLUTION:

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.

K'
A: 

Hi everybody! Did you ever find a working solution to the problem?

Regards Henry

henmue