[Swift UI]一、基础控件-(17)如何对图像视图进行缩放和旋转
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(let_us_code)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址: https://www.cnblogs.com/strengthen/p/12266907.html
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
本文将演示图像视图的缩放和旋转。
1 import SwiftUI 2 3 struct ContentView : View 4 { 5 var body: some View 6 { 7 ScrollView 8 { 9 VStack 10 { 11 //添加第一个图像视图 12 Image("girlPicture") 13 //将图像视图缩小到原来的0.8倍 14 .scaleEffect(0.8) 15 16 //添加第二个图像视图 17 Image("girlPicture") 18 //可以对图像视图的宽度和高度应用不同的缩放比例。 19 //宽度放大为1.2倍。 20 //高度缩小为0.5倍。 21 .scaleEffect(CGSize(width: 1.2, height: 1)) 22 23 //添加第三个图像视图 24 Image("girlPicture") 25 //在默认情况下,图像视图的缩放锚点位于图像视图的中心位置。 26 //此时将图像视图的缩放锚点,修改为左下角。 27 .scaleEffect(x: 1.5, y: 1, anchor: UnitPoint.bottomLeading) 28 } 29 30 VStack 31 { 32 //添加第一个图像视图 33 Image("girlPicture") 34 //给图像视图应用旋转效果 35 //并设置旋转角度为90度 36 .rotationEffect(Angle.init(degrees: 90)) 37 38 //添加第二个图像视图 39 Image("girlPicture") 40 //在默认情况下,图像视图的缩放锚点位于图像视图的中心位置。 41 //此时将图像视图的缩放锚点,修改为左上角 42 .rotationEffect(Angle.init(degrees: 30), anchor: UnitPoint.init(x: 0, y: 0)) 43 44 //添加第三个图像视图 45 Image("girlPicture") 46 //图像视图可以在三个轴f向上进行旋转操作, 47 //X轴是水平方向 48 //Y轴是垂直方向 49 //Z轴是垂直于屏幕的方向 50 //这里设置图像沿着水平方向旋转45度 51 .rotation3DEffect(Angle.init(degrees: 45), axis: (x: CGFloat(0), y: CGFloat(1), z: CGFloat(0))) 52 } 53 } 54 } 55 } 56 57 #if DEBUG 58 struct ContentView_Previews : PreviewProvider { 59 60 @State var txtFieldValue : String 61 62 63 static var previews: some View { 64 ContentView() 65 } 66 } 67 #endif

浙公网安备 33010602011771号