Reputation: 411
I want to transform UIView
from portrait to landscape mode and make it fullscreen. How can I do that?
CGFloat degrees = 90;
CGAffineTransform transform = CGAffineTransformMakeRotation((M_PI * degrees / 180.0f));
[UIView animateWithDuration:0.3f animations:^{
transitionView.transform = transform;
// How to set the origin to make it fullscreen?
} completion:^(BOOL finished) {
}];
Upvotes: 1
Views: 2551
Reputation: 294
Translate to match new origin (because rotation is performed around the view center point)
UIView.animate(withDuration: 0.3) {
self.frame = CGRect(origin: .zero, size: CGSize(width: UIScreen.main.bounds.height,
height: UIScreen.main.bounds.width))
let rotate = CGAffineTransform(rotationAngle: -.pi / 2)
let center = self.view.center
let translate = CGAffineTransform(translationX: center.x + center.y - self.bounds.width,
y: center.y - center.x)
self.transform = translate.concatenating(rotate)
}
Upvotes: 1
Reputation: 408
Here the solution in swift 4
if UIDeviceOrientationIsLandscape(UIDevice.current.orientation){
let screenSize = UIScreen.main.bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
videoView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
playerLayer.frame = videoView.bounds
}
Upvotes: 0
Reputation: 1384
You have to select the view and give constraints to that view such that it sticks with the margin (as shown below). Then it will automatically stretch to full screen.
You can also use size classes, and set different constraints for landscape and portrait mode.
Upvotes: 0