gpt4 book ai didi

ios - 在 iOS 7 上,在 viewDidLoad 中设置图层变换会破坏自动布局

转载 作者:行者123 更新时间:2023-12-01 16:39:38 25 4
gpt4 key购买 nike

在 iOS 7 上,对 viewDidLoad 中的 View 层应用变换似乎打破了自动布局。

在一个新项目中,我创建了两个 View ,一个红色和一个绿色,并赋予它们相同的约束(在 super View 中水平居中、与顶部布局指南的距离、宽度和高度)。该应用程序通常看起来像这样(红色 View 被完全覆盖):



然后我做了ViewController.swift看起来像这样:

import UIKit
import QuartzCore

class ViewController: UIViewController {

@IBOutlet var subview: UIView?

override func viewDidLoad() {
super.viewDidLoad()

subview!.layer.transform = CATransform3DMakeScale(0.6, 0.6, 1)

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(1 * NSEC_PER_SEC)), dispatch_get_main_queue()) {
self.subview!.layer.transform = CATransform3DIdentity
}
}
}

应用转换后,应用程序看起来像这样(请注意,转换的来源是错误的):



删除转换后,应用程序看起来像这样(注意绿色 View 在错误的位置):



错误的定位似乎会持续 View 的整个生命周期。我做错了什么还是这是一个直接的错误?有没有其他人遇到过它并找到了一个干净的解决方法?

最佳答案

尝试使用

subview!.transform = CGAffineTransformMakeScale(0.6, 0.6)

代替
subview!.layer.transform = CATransform3DMakeScale(0.6, 0.6, 1)

我有一个类似的问题,这有帮助。答案灵感:
how to reset the view position to origin after scale

关于ios - 在 iOS 7 上,在 viewDidLoad 中设置图层变换会破坏自动布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25515931/

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