ca-archived / iOS-NBUImagePicker

Modular image picker with Simulator-compatible AVFondation camera, assets library, filters and more.
http://cyberagent.github.io/iOS-NBUImagePicker
Apache License 2.0
193 stars 48 forks source link

Initialize NBUCameraView in viewDidAppear or viewDidLayoutSubviews #8

Closed toyhunter closed 10 years ago

toyhunter commented 10 years ago

Currently I have an issue to configure NBUCameraView's bound. I use auto layout, and it seems to me view's bound is not determined until viewDidAppear or viewDidLayoutSubviews. However, I notice NBUCameraView is initialized in viewWillAppear which makes its bound incorrectly configured.

Is it possible to change this initialization behavior or to perform initialization manually?

rivera-ernesto commented 10 years ago

The view's frame (and thus its bounds) is determined in viewWillAppear.

After reading this though it seems that I should make these calculations in viewWillLayoutSubviews.

rivera-ernesto commented 10 years ago

Sorry, just checked again, and this special viewWillAppear is in fact a message sent when the view is going to get added to a window.

If I understand, your problem is that the _previewLayer.frame is not resized automatically if the camera view changes sizes afterwards right?

toyhunter commented 10 years ago

Exactly. Have I done something wrong for auto layout to get worked?

toyhunter commented 10 years ago

To clarify my problem, I use .xib with iphone5 layout. So at runtime the problem will occur if I run my app on, for example, iphone4s where camera view will have its bound determined after viewWillAppear.

rivera-ernesto commented 10 years ago

Can you try readjusting _previewLayer.frame in NBUCameraView?

http://stackoverflow.com/a/4098348/1049134

If that works please pull request the changes.

toyhunter commented 10 years ago

Readjusting the frame in layoutSubviews did solve my problem. Thank you so much, @rivera-ernesto.

rivera-ernesto commented 10 years ago

Thanks to you!