iphone - CGAffineTransform Scale 在设备旋转后修改

标签 iphone ios uiview cgaffinetransform cgaffinetransformscale

我认为我正在执行转换

originalTransform = self.appContainer.transform;
self.appContainer.transform = CGAffineTransformMakeScale(.8, .8);

Original Rotation

如果我不旋转设备,我可以通过使用将其恢复到原来的状态

self.appContainer.transform = CGAffineTransformScale(originalTransform, 1, 1);

不幸的是,如果我旋转设备, View 的变换矩阵会被 View 旋转修改并破坏原始比例。如果我在旋转后撤消比例,我会看到 UIView 没有恢复到原来的完整大小。

After Rotation

After Original Scale

我确定我需要在原始变换矩阵和新变换矩阵之间进行计算,但我不确定如何执行此操作。我唯一能做的就是在旋转之前将比例恢复为 1

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    self.appContainer.transform = CGAffineTransformScale(originalTransform, 1, 1);
}

然后在

之后用新修改的变换重新缩放它
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation               {
    self.appContainer.transform = CGAffineTransformMakeScale(.8, .8);
}

这使它按我预期的方式工作,但我不想返回全屏,然后返回 .8 比例,我希望它从新转换到正确的 .8 比例。

最佳答案

如果您想将其恢复为原始状态,请尝试将转换设置为 CGAffineTransform Identity。

self.appContainer.transform = CGAffineTransformIdentity;

关于iphone - CGAffineTransform Scale 在设备旋转后修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10519735/

相关文章:

iPhone 后台应用程序 - 为什么 Whatsapp 可以工作而 Skype 不行

iphone - HTML 内容适合 UIWebview 而无需缩小

ios - 捕捉 UIView 内容重绘

iphone - ASIHTTPRequest POST iPhone

iOS 6 bluetoothmanager 配对专用 api

ios - UIImagePickerController 照片预览被未知黑框遮挡

ios - 我们可以在应用程序尚未完成仍在开发时提交 iOS 应用程序以供 facebook 登录审核吗?

ios - Alamofire json 请求 Swift 3

ios - 我如何从 xib 创建自定义 uiview

ios - 按下按钮时 KLCPopup 错误