gpt4 book ai didi

iphone - 转换矩形 :toView: works different on iPad retina and iPad 2

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:57 25 4
gpt4 key购买 nike

我的这段代码在 iPad2 上完美运行,但在 Retina iPad 上缩放错误。

我在两台 iPad 上都执行了该应用程序,但行为完全不同。在 Retina iPad 上,图像返回到原始位置并且不会发生转换。

代码采用一组 View ,将它们添加到临时 View ,调整临时 View 的大小,然后将这些 View 添加回去,这样我就可以同时调整所有 View 的大小。

- (IBAction)scaleParts:(UIPinchGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
self.tempCanvasView = [[UIView alloc] initWithFrame:self.canvas.bounds];
self.tempCanvasView.backgroundColor = [UIColor redColor];
for (UIView *view in [self.canvas subviews]) {
CGRect currentFrame = view.bounds;
CGRect newFrame = [view convertRect:currentFrame toView:self.tempCanvasView];
view.bounds = newFrame;
[self.tempCanvasView addSubview:view];
}
[self.canvas addSubview:self.tempCanvasView];
} else if (sender.state == UIGestureRecognizerStateChanged) {
self.tempCanvasView.transform = CGAffineTransformScale(self.tempCanvasView.transform, sender.scale, sender.scale);
sender.scale = 1.0;
} else if (sender.state == UIGestureRecognizerStateEnded) {
for (UIView *view in [self.tempCanvasView subviews]) {
CGRect currentFrame = view.bounds;
CGRect newFrame = [view convertRect:currentFrame toView:self.canvas];
view.frame = newFrame;
[self.canvas addSubview:view];
}
[self.tempCanvasView removeFromSuperview];
self.tempCanvasView = nil;
}
}

最佳答案

也许您需要检测应用程序使用的屏幕类型(iPad 的比例=1,iPadRetina 的比例=2)。

CGFloat scale = [[UIScreen mainScreen] scale];

在那之后..

 if (scale==1) {
//code from above
} else {
//code from above with small modification
}

关于iphone - 转换矩形 :toView: works different on iPad retina and iPad 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401299/

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