【问题标题】:Rotate a UIImageView according to UIWindow Orientations?根据 UIWindow 方向旋转 UIImageView?
【发布时间】:2012-08-17 11:14:40
【问题描述】:

我在 UIWindow 的底部有一个 UIImageView。我希望它始终在底部显示它,无论方向是什么,但在实现它时遇到了麻烦。有什么解决办法吗?

【问题讨论】:

    标签: ios4 uiimageview image-rotation


    【解决方案1】:
    NSLog(@"rotate");
    
    if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)){
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    
        // Rotate 90 degrees to hide it off screen
        CGAffineTransform rotationTransform = CGAffineTransformIdentity;
        rotationTransform = CGAffineTransformRotate(rotationTransform,DegreesToRadians(0));
        delegate.imgV.transform = rotationTransform;
    
    }
    else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate; 
    
        // Rotate 90 degrees to hide it off screen
        CGAffineTransform rotationTransform = CGAffineTransformIdentity;
        rotationTransform = CGAffineTransformRotate(rotationTransform,DegreesToRadians(90));
        delegate.imgV.transform = rotationTransform;
    
    }
    

    享受:-)

    【讨论】:

    • DegreesToRadians 是定义值。比如——#define DegreesToRadians(x) (M_PI * (x) / 180.0)
    • 我也添加了#define,但它不工作见截图
    • 在设备定向时尝试更改图像视图框架大小。
    • 我认为窗口方向总是纵向的。您应该检查 uidevice 方向并设置 imageview 转换。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 2012-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多