美文网首页
flutter 加载原生view

flutter 加载原生view

作者: FlowYourHeart | 来源:发表于2024-01-15 15:38 被阅读0次

    delegate.m didFinishLaunchingWithOptions

            GeneratedPluginRegistrant.register(with: self)
              let registrar = self.registrar(forPlugin: "FlutterIosPay")!
              let factory = MyPlatformViewFactory(messenger: registrar.messenger())
              registrar.register(factory, withId: "FlutterIosPay/custom_platform_view")
              Flutter2OCBridge.register(with: registrar);
    

    MyPlatformViewFactory

    import UIKit
    import Flutter
    class MyPlatformViewFactory: NSObject, FlutterPlatformViewFactory {
         var messenger: FlutterBinaryMessenger
        init(messenger:FlutterBinaryMessenger) {
           self.messenger = messenger
           super.init()
         }
        func create(withFrame frame: CGRect, viewIdentifier viewId: Int64, arguments args: Any?) -> FlutterPlatformView {
            return MyPlatformView(frame: frame, viewIdentifier: viewId, arguments: args, binaryMessenger: self.messenger)
         }
         
         func createArgsCodec() -> FlutterMessageCodec & NSObjectProtocol {
           return FlutterStandardMessageCodec.sharedInstance()
         }
        
      }
    

    MyPlatformView

    import Flutter
    import UIKit
    
    class MyPlatformView: NSObject, FlutterPlatformView {
        var _view: UIView
        
        init(frame: CGRect, viewIdentifier: Int64, arguments: Any?, binaryMessenger: FlutterBinaryMessenger) {
            print("---------------->webview frame:\(frame) <-------------");
            _view = UIView(frame: frame)
            if arguments is NSDictionary {
                let dict = arguments as! NSDictionary
                if(dict["page"] as! String == "portalWebView"){
                    let tView = PortalWebView(frame: frame)
                    tView.transferDataDic = arguments as! [AnyHashable : Any];
                    _view = tView;
                }
                
                
            }else{
               
            }
            
        }
    
        func view() -> UIView {
                  
            return _view
        }
    }
    

    相关文章

      网友评论

          本文标题:flutter 加载原生view

          本文链接:https://www.haomeiwen.com/subject/yyjhodtx.html