Repository: flutter
Issue: `UiKitView` is transformed incorrectly when applying a perspective transformation with a non-left Alignment
Labels: platform-ios,a: platform-views,has reproducible steps,P2,team-ios,triaged-ios,found in release: 3.24,found in release: 3.27

### Steps to reproduce

Try the sample code (or repository at https://github.com/kekland/calayer_impeller_transform)

1. Try to set any left alignment (vertical alignment doesn't matter). Observe that when changing the slider, the applied transformation is correct both for the Flutter widget and the iOS widget
2. Try to set non-left alignment (e.g. center / right). Now, when dragging the slider, the iOS view (blue) deviates from the Flutter widget (orange)

### Expected results

Both views should be transformed in the same way

### Actual results

When setting `alignment: Alignment.centerRight` (or any other center/right alignment), the iOS view deviates from the Flutter widget

### Code sample

<details open><summary>Code sample</summary>

main.dart:
```dart
import 'dart:math';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var angle = 0.0;
  var alignment = Alignment.centerLeft;
  
  static const _alignmentValues = [
    Alignment.topLeft,
    Alignment.topCenter,
    Alignment.topRight,
    Alignment.centerLeft,
    Alignment.center,
    Alignment.centerRight,
    Alignment.bottomLeft,
    Alignment.bottomCenter,
    Alignment.bottomRight,
  ];

  @override
  Widget build(BuildContext context) {
    final transform = Matrix4.identity()
      ..setEntry(3, 2, 0.00125)
      ..rotateY(angle);

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Column(
        children: [
          Slider(
            value: angle,
            onChanged: (v) => setState(() => angle = v),
            min: -pi / 2,
            max: pi / 2,
          ),
          DropdownButton<Alignment>(
            value: alignment,
            onChanged: (v) => setState(() => alignment = v!),
            items: _alignmentValues
                .map((e) => DropdownMenuItem(
                      value: e,
                      child: Text(e.toString()),
                    ))
                .toList(),
          ),
          Center(
            child: DecoratedBox(
              decoration: BoxDecoration(
                border: Border.all(color: Colors.black),
              ),
              child: Transform(
                transform: transform,
                alignment: alignment,
                child: const Stack(
                  children: [
                    Opacity(
                      opacity: 0.5,
                      child: MyFlutterView(),
                    ),
                    Opacity(
                      opacity: 0.5,
                      child: MyPlatformView(),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

class MyFlutterView extends StatelessWidget {
  const MyFlutterView({super.key});

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: 160.0,
      height: 160.0,
      child: Container(
        color: Colors.orange,
        child: const Text('Text from Flutter'),
      ),
    );
  }
}

class MyPlatformView extends StatelessWidget {
  const MyPlatformView({super.key});

  @override
  Widget build(BuildContext context) {
    return const SizedBox(
      width: 160.0,
      height: 160.0,
      child: UiKitView(
        viewType: 'MyPlatformView',
      ),
    );
  }
}
```

AppDelegate.swift (code taken from https://docs.flutter.dev/platform-integration/ios/platform-views)
```swift
import Flutter
import UIKit

@main
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
      
      guard let pluginRegistrar = self.registrar(forPlugin: "plugin-name") else { return false }

      let factory = FLNativeViewFactory(messenger: pluginRegistrar.messenger())
      pluginRegistrar.register(
          factory,
          withId: "MyPlatformView")
      
      return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

class FLNativeViewFactory: NSObject, FlutterPlatformViewFactory {
    private var messenger: FlutterBinaryMessenger

    init(messenger: FlutterBinaryMessenger) {
        self.messenger = messenger
        super.init()
    }

    func create(
        withFrame frame: CGRect,
        viewIdentifier viewId: Int64,
        arguments args: Any?
    ) -> FlutterPlatformView {
        return FLNativeView(
            frame: frame,
            viewIdentifier: viewId,
            arguments: args,
            binaryMessenger: messenger)
    }

    /// Implementing this method is only necessary when the `arguments` in `createWithFrame` is not `nil`.
    public func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
          return FlutterStandardMessageCodec.sharedInstance()
    }
}

class FLNativeView: NSObject, FlutterPlatformView {
    private var _view: UIView

    init(
        frame: CGRect,
        viewIdentifier viewId: Int64,
        arguments args: Any?,
        binaryMessenger messenger: FlutterBinaryMessenger?
    ) {
        _view = UIView()
        super.init()
        // iOS views can be created here
        createNativeView(view: _view)
    }

    func view() -> UIView {
        return _view
    }

    func createNativeView(view _view: UIView){
        _view.backgroundColor = UIColor.blue
        let nativeLabel = UILabel()
        nativeLabel.text = "Native text from iOS"
        nativeLabel.textColor = UIColor.white
        nativeLabel.textAlignment = .center
        nativeLabel.frame = CGRect(x: 0, y: 0, width: 180, height: 48.0)
        _view.addSubview(nativeLabel)
    }
}
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

(Orange is Flutter, Blue is iOS)

https://github.com/user-attachments/assets/0f68df52-06c5-4004-aa33-50b6bf0b476a

</details>


### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.24.3, on macOS 15.0 24A335 darwin-arm64, locale en-US)
    • Flutter version 3.24.3 on channel stable at /Users/kekland/fvm/versions/3.24.3
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (5 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc4)
    • Android SDK at /Users/kekland/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0-rc4
    • ANDROID_HOME = /Users/kekland/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16A242d
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.94.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.99.20240930

[✓] Connected device (4 available)
    • Erzhan’s iPhone 11 Pro (mobile) • 00008030-001839EC21FB802E • ios            • iOS 18.0.1 22A3370
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 15.0 24A335 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 15.0 24A335 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 129.0.6668.101
    ! Error: Browsing on the local area network for Hellomik. Ensure the device is unlocked and attached with a cable or associated with the
      same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)

[✓] Network resources
    • All expected network network resources are available.
```

</details>