gpt4 book ai didi

ios - 使用 Swift 在 iOS 中将 CFAffineTransformRotation 应用于父 View 时禁用 subview 的自动旋转?

转载 作者:行者123 更新时间:2023-11-28 13:27:11 26 4
gpt4 key购买 nike

让我们考虑一下,在 ViewController 中,我有一个 View 和 5 个按钮,它们是该 View 的 subview 。我的问题是,当我应用 CGAffineTransform.identity.rotated 来查看时,它的旋转完美如我所料。但是那 5按钮也朝那个旋转,我不想旋转按钮。谁能告诉我,我希望那个按钮不应该朝父 View 旋转。我对按钮应用了相反的角度,但按钮的大小正在调整。

    UIViewController(portrait mode)
UIView(should rotate)
button1(shouldn't rotate)
button2(shouldn't rotate).......
button5(shouldn't rotate)

func locationManager(_ manager: CLLocationManager, didUpdateHeading heading: CLHeading) {


let maxLat: Double = fmax(userLocation.latitude, userLocation.latitude)
let maxLon: Double = fmax(userLocation.longitude, userLocation.longitude)
let minLat: Double = fmin(userLocation.latitude, userLocation.latitude)
let minLon: Double = fmin(userLocation.longitude, userLocation.longitude)
let center: CLLocationCoordinate2D = CLLocationCoordinate2DMake((maxLat + minLat) / 2, (maxLon + minLon) / 2)
angle2U = getBearing(toPoint: center, longitude: userLocation.longitude, latitude: userLocation.latitude)
let direction2G = CGFloat(heading.magneticHeading * Double.pi/180)
DispatchQueue.main.async {
let direction2GN = CGFloat(self.angle2U) - direction2G
let final_transform = CGAffineTransform.identity.rotated(by: direction2GN)
self.compass_view.transform = final_transform
self.optionbutton1.transform = compass_view.transform.inverted()
self.option_button2.transform = compass_view.transform.inverted()
self.option_button3.transform = compass_view.transform.inverted()
self.option_button4.transform = compass_view.transform.inverted()
self.option_button5.transform = compass_view.transform.inverted()

}
}

最佳答案

您应该向后旋转按钮。

您可以使用 inverted()为了那个原因。例如:

let transform = // your CGAffineTransform
view.transform = transform
button1.transform = transform.inverted()
...
button5.transform = transform.inverted()

或者:

button1.transform = yourRotatedView.transform.inverted()
...
button5.transform = yourRotatedView.transform.inverted()

关于ios - 使用 Swift 在 iOS 中将 CFAffineTransformRotation 应用于父 View 时禁用 subview 的自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58155980/

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