如何在不使用Viewbox的情况下缩放XAML中的弧段

时间:2019-11-03 02:08:51

标签: wpf xaml

我想像分割线段一样缩放圆弧段。我不想使用Viewbox,因为这会在调整窗口大小时增加/减小线的粗细。在我的示例中,我有一个适当缩放的线段,并且我想类似地缩放弧段。如何在XAML中完成?

import UIKit
import GoogleMaps
import RxCoreLocation
import RxSwift

class MapViewController: UIViewController {
    private var mapView: GMSMapView?
    private let disposeBag = DisposeBag()
    private let manager = CLLocationManager()

    override func viewDidLoad() {
        super.viewDidLoad()
        manager.requestWhenInUseAuthorization()
        manager.startUpdatingLocation()

        let camera = GMSCameraPosition.camera(withLatitude: 0, longitude: 0, zoom: 17.0)
        mapView = GMSMapView.map(withFrame: .zero, camera: camera)
        view = mapView

        manager.rx
            .didUpdateLocations
            .subscribe(onNext: { [weak self] in
                guard let location = $0.locations.last else { return }
                let camera = GMSCameraPosition.camera(withLatitude: location.coordinate.latitude, longitude: location.coordinate.longitude, zoom: 17.0)
                self?.mapView?.animate(to: camera)
                self?.manager.stopUpdatingLocation()
            })
            .disposed(by: disposeBag)
    }
}

1 个答案:

答案 0 :(得分:1)

您将以与缩放LineGeometry相同的方式缩放PathGeometry,即,将ScaleTransform分配给其Transform属性。

使用与LineGeometry相同的ScaleTransform时,还需要使用从0到1的相同坐标范围。

<Path Stroke="White" StrokeThickness="1">
    <Path.Data>
        <PathGeometry Transform="{StaticResource transform}">
            <PathGeometry.Figures>
                <PathFigureCollection>
                    <PathFigure StartPoint="0.1,0.2">
                        <PathFigure.Segments>
                            <PathSegmentCollection>
                                <ArcSegment Size="0.4,0.3" Point="1,1"
                                            RotationAngle="45" IsLargeArc="True"
                                            SweepDirection="CounterClockwise"/>
                            </PathSegmentCollection>
                        </PathFigure.Segments>
                    </PathFigure>
                </PathFigureCollection>
            </PathGeometry.Figures>
        </PathGeometry>
    </Path.Data>
</Path>

您还可以在GeometryGroup中绘制具有多个几何图形的单个路径:

<Path Stroke="White" StrokeThickness="1">
    <Path.Data>
        <GeometryGroup Transform="{StaticResource transform}">
            <LineGeometry StartPoint="0.01,0.01" EndPoint="0.99,0.99"/>
            <PathGeometry>
                <PathGeometry.Figures>
                    ...
                </PathGeometry.Figures>
            </PathGeometry>
        </GeometryGroup>
    </Path.Data>
</Path>