gpt4 book ai didi

ios - 如何将 UIView 转换为横向和全屏?

转载 作者:行者123 更新时间:2023-11-29 11:48:24 24 4
gpt4 key购买 nike

我想将 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) {
}];

最佳答案

  1. 通过交换高度和宽度来改变 View 框架
  2. 旋转-90度(逆时针)
  3. 平移以匹配新原点(因为旋转是围绕 View 中心点执行的)

    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)
    }

关于ios - 如何将 UIView 转换为横向和全屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42289057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com