Exemplo n.º 1
0
        bool IViewHierarchyHandler.TryGetRepresentedView(object view, bool withSubviews, out IInspectView representedView)
        {
            var uiview = view as UIView;

            if (uiview != null)
            {
                representedView = new iOSInspectView(uiview, withSubviews);
                return(true);
            }

            representedView = null;
            return(false);
        }
Exemplo n.º 2
0
        public iOSInspectView(UIView view, bool withSubviews = true)
        {
            if (view == null)
            {
                throw new ArgumentNullException(nameof(view));
            }

            this.view = view;

            PopulateTypeInformationFromObject(view);

            // FIXME: special case certain view types and fill in the Description property

            if (view is UILabel)
            {
                Description = ((UILabel)view).Text;
            }
            else if (view is UIButton)
            {
                Description = ((UIButton)view).TitleLabel.Text;
            }
            else if (view is UITextField)
            {
                Description = ((UITextField)view).Text;
            }

            if (!view.Transform.IsIdentity)
            {
                var transform = CGAffineTransform.MakeIdentity();
                transform.Translate(-view.Bounds.Width * .5f, -view.Bounds.Height * .5f);
                transform = CGAffineTransform.Multiply(transform, view.Transform);
                transform.Translate(view.Center.X, view.Center.Y);
                Transform = new ViewTransform {
                    M11     = transform.xx,
                    M12     = transform.yx,
                    M21     = transform.xy,
                    M22     = transform.yy,
                    OffsetX = transform.x0,
                    OffsetY = transform.y0
                };
                X      = view.Bounds.X;
                Y      = view.Bounds.Y;
                Width  = view.Bounds.Width;
                Height = view.Bounds.Height;
            }
            else
            {
                X      = view.Frame.X;
                Y      = view.Frame.Y;
                Width  = view.Frame.Width;
                Height = view.Frame.Height;
            }
            Kind       = ViewKind.Primary;
            Visibility = view.Hidden ? ViewVisibility.Collapsed : ViewVisibility.Visible;

            if (!withSubviews)
            {
                var point = view.ConvertPointToView(
                    new CoreGraphics.CGPoint(0, 0),
                    null);

                X = point.X;
                Y = point.Y;
                return;
            }

            // MKMapView has a subview that is so large (5901507x5901507 in the case encountered)
            // that it causes the SceneKit camera to zoom out so much that every other node is
            // effectively hidden. This should ideally be fixed in the client.
            if (view is MapKit.MKMapView)
            {
                return;
            }

            var visitedLayers = new HashSet <IntPtr> ();

            var subviews = view.Subviews;

            if (subviews != null && subviews.Length > 0)
            {
                for (int i = 0; i < subviews.Length; i++)
                {
                    var subview = new iOSInspectView(subviews [i]);
                    AddSubview(subview);

                    if (subview.Layer == null)
                    {
                        continue;
                    }

                    // After calling AddSubview, add any visited layers to the list. We track
                    // visited layers here so that when we actually recurse into the layer that
                    // belongs to this view, we don't duplicate things. This is needed because of
                    // the pointer-into-a-tree nature of layers, as explained above in the constructor
                    // remarks.
                    var subviewLayer = (iOSInspectView)subview.Layer;
                    if (subviewLayer.layer != null)
                    {
                        visitedLayers.Add(subviewLayer.layer.Handle);
                    }

                    subviewLayer.layer?.Sublayers?.ForEach(
                        layer => visitedLayers.Add(layer.Handle));
                }
            }

            if (view.Layer != null && !visitedLayers.Contains(view.Layer.Handle))
            {
                Layer = new iOSInspectView(view, view.Layer, visitedLayers)
                {
                    Parent = this
                }
            }
            ;
        }