Eric Brotto
Eric Brotto

Reputation: 54261

UIImagePickerController pushing views up 20px

I have a modal view controller containing:

    imagePickerController_ = [[UIImagePickerController alloc] init];
    imagePickerController_.delegate = (id)self;
    imagePickerController_.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController_.view.frame = CGRectMake(0.0f, -20.0f, 320.0f, 480.0f);
    [self.view addSubview:imagePickerController_.view];

You'll notice I have had to manually move the view up 20px because for some reason it was sitting too low.

When I dismiss the modal view controller all the views contained within the view of the view controller beneath get pushed up 20px (even though the view itself keeps the same original coordinates).

In other words I have a view controller A which controls view A. View A also contains view B, C and D. I then push modal view controller X onto view controller A to show an image picker controller with the code above. When modal view controller X gets dismissed view controller A is shown again with view A intact, but views B, C and D are moved 20px up. How can I prevent this from happening?

Upvotes: 3

Views: 1173

Answers (2)

Eric Brotto
Eric Brotto

Reputation: 54261

I've discovered what the problem was. Unfortunately it would have been difficult to see the error from my post.

I was placing the imagePickerController in another view controller which was being presented modally. I am now directly presenting modally the imagePickerController.

imagePickerController_ = [[UIImagePickerController alloc] init];
imagePickerController_.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController_.delegate = (id)self;
[self presentModalViewController:imagePickerController_ animated:YES]; 

Sorry for the hassle. I hope this helps others not to make the same mistake!

Upvotes: 1

DanSkeel
DanSkeel

Reputation: 4005

I guess, when you add that imagePickerController_ you need to set it's frame to bounds of A viewController. Like imagePickerController_.view.frame = self.view.bounds.


You can find more about view coordinate systems at View and Window Architecture.

Also read about naming conventions, naming imagePickerController_ pretty strange. May be you meant _imagePickerController. And I think it's better to use properties for this purpose. So access it with self.imagePickerController.

Also check out Presenting View Controllers from Other View Controllers.

Upvotes: 0

Related Questions