当前位置: 首页>>代码示例>>C#>>正文


C# CALayer.LayoutSublayers方法代码示例

本文整理汇总了C#中CALayer.LayoutSublayers方法的典型用法代码示例。如果您正苦于以下问题:C# CALayer.LayoutSublayers方法的具体用法?C# CALayer.LayoutSublayers怎么用?C# CALayer.LayoutSublayers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CALayer的用法示例。


在下文中一共展示了CALayer.LayoutSublayers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnUpdateNativeControl

		void OnUpdateNativeControl(CALayer caLayer)
		{
			var view = Renderer.Element;
			var uiview = Renderer.NativeView;

			if (view == null || view.Batched)
				return;

			var shouldInteract = !view.InputTransparent && view.IsEnabled;
			if (_isInteractive != shouldInteract)
			{
				uiview.UserInteractionEnabled = shouldInteract;
				_isInteractive = shouldInteract;
			}

			var boundsChanged = _lastBounds != view.Bounds;

			var thread = !boundsChanged && !caLayer.Frame.IsEmpty;

			var anchorX = (float)view.AnchorX;
			var anchorY = (float)view.AnchorY;
			var translationX = (float)view.TranslationX;
			var translationY = (float)view.TranslationY;
			var rotationX = (float)view.RotationX;
			var rotationY = (float)view.RotationY;
			var rotation = (float)view.Rotation;
			var scale = (float)view.Scale;
			var width = (float)view.Width;
			var height = (float)view.Height;
			var x = (float)view.X;
			var y = (float)view.Y;
			var opacity = (float)view.Opacity;
			var isVisible = view.IsVisible;

			var updateTarget = Interlocked.Increment(ref _updateCount);

			Action update = () =>
			{
				if (updateTarget != _updateCount)
					return;

				var visualElement = view;
				var parent = view.RealParent;

				var shouldRelayoutSublayers = false;
				if (isVisible && caLayer.Hidden)
				{
					caLayer.Hidden = false;
					if (!caLayer.Frame.IsEmpty)
						shouldRelayoutSublayers = true;
				}

				if (!isVisible && !caLayer.Hidden)
				{
					caLayer.Hidden = true;
					shouldRelayoutSublayers = true;
				}

				// ripe for optimization
				var transform = CATransform3D.Identity;

				// Dont ever attempt to actually change the layout of a Page unless it is a ContentPage
				// iOS is a really big fan of you not actually modifying the View's of the UIViewControllers
				if ((!(visualElement is Page) || visualElement is ContentPage) && width > 0 && height > 0 && parent != null && boundsChanged)
				{
					var target = new RectangleF(x, y, width, height);
					// must reset transform prior to setting frame...
					caLayer.Transform = transform;
					uiview.Frame = target;
					if (shouldRelayoutSublayers)
						caLayer.LayoutSublayers();
				}
				else if (width <= 0 || height <= 0)
				{
					caLayer.Hidden = true;
					return;
				}

				caLayer.AnchorPoint = new PointF(anchorX, anchorY);
				caLayer.Opacity = opacity;
				const double epsilon = 0.001;

				// position is relative to anchor point
				if (Math.Abs(anchorX - .5) > epsilon)
					transform = transform.Translate((anchorX - .5f) * width, 0, 0);
				if (Math.Abs(anchorY - .5) > epsilon)
					transform = transform.Translate(0, (anchorY - .5f) * height, 0);

				if (Math.Abs(translationX) > epsilon || Math.Abs(translationY) > epsilon)
					transform = transform.Translate(translationX, translationY, 0);

				if (Math.Abs(scale - 1) > epsilon)
					transform = transform.Scale(scale);

				// not just an optimization, iOS will not "pixel align" a view which has m34 set
				if (Math.Abs(rotationY % 180) > epsilon || Math.Abs(rotationX % 180) > epsilon)
					transform.m34 = 1.0f / -400f;

				if (Math.Abs(rotationX % 360) > epsilon)
					transform = transform.Rotate(rotationX * (float)Math.PI / 180.0f, 1.0f, 0.0f, 0.0f);
//.........这里部分代码省略.........
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:101,代码来源:VisualElementTracker.cs


注:本文中的CALayer.LayoutSublayers方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。