Introduce a view controller that is half the size of the screen

I am trying to present a view controller that is only half the height using

[self presentModalViewController:menu animated:YES]; 

The problem is when it was presented, the view controller ends up the same size as the screen. I also tried to make the β€œmenu” the full size of the screen and change the transparency of the view to white, but this also does not work.

+6
source share
3 answers

Just use the main animated or animated transitions with a UIView that is half the size of the screen. You will need a holder view, which you add to the main view.

Place the half-size view under the screen (halfView.y = 480 or 320 depending on orientation).

Animate it up.

Something like this might be:

 // set up an animation for the transition between the views CATransition *animation = [CATransition animation]; [animation setDuration:0.5]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromBottom]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [holderView addAnimation:animation forKey:@"SwitchToView1"]; 
+8
source

On iPhone and iPod touch devices, viewing the modalViewController is always full screen. On an iPad, the presentation depends on the value in the modalPresentationStyle property.

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

If you want to cover only part of the screen, you can make an animation that will hide the UIView container and everything that you want to show at the position on the screen.

I would recommend you read this post: A transparent modal view on the navigation controller

"I tried to make the background of the view white"

This would not affect the work, you could write [UIColor clearColor] , however, the view of the controller that is covered by the modal will disappear from the screen when the animation is completed. Therefore, if you make a white background, you will probably end up looking at the Windows background, which is white and not what you want.

+5
source

You really don't want to try this with the UIViewController. Add a UIView to the current controller view, give this view its own controller object not a UIViewController if it needs to control its behavior.

I talked about some details about how you are trying to do this outside of the contract provided by the UIViewController here: http://blog.carbonfive.com/2011/03/09/abusing-uiviewcontrollers/

0
source

Source: https://habr.com/ru/post/886805/


All Articles