我想将UIView
从纵向模式转换为横向模式,并将其设为全屏模式。我怎么能这样做?
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) {
}];
答案 0 :(得分:0)
答案 1 :(得分:0)
这里是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
}
答案 2 :(得分:0)
平移以匹配新的原点(因为围绕视图中心点执行旋转)
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)
}