- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 2 行(标题和内容)的控件。当指针进入或存在时,内容上有一个 ScaleY 变换,但当内容缩放为 0 时,高度为 Auto 的行似乎不会折叠高度。
<Page
x:Class="ScaleTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ScaleTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<local:TestControl VerticalAlignment="Bottom"/>
</Grid>
<Style TargetType="local:TestControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TestControl">
<Grid VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="DisplayStates">
<VisualState x:Name="Minimized">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="contentTransForm"
Storyboard.TargetProperty="ScaleY"
Duration="0:0:0.2"
To="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Maximized">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="contentTransForm"
Storyboard.TargetProperty="ScaleY"
Duration="0:0:0.2"
To="1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid Background="Red">
<TextBlock Text="Header"/>
</Grid>
<Grid Grid.Row="1" Background="Orange">
<Grid.RenderTransform>
<CompositeTransform x:Name="contentTransForm" ScaleY="0" ScaleX="1"/>
</Grid.RenderTransform>
<TextBlock Text="Content"/>
</Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我制作了一个小示例应用程序来展示问题。 sample
为什么网格没有更新。
最佳答案
谢谢大家,
我实际上是通过从 wpf 工具包中实现 LayoutTansformer 并使用调解器和转换器来解决它的。它提供了一个很好的流畅动画,不会熬夜然后突然崩溃。
布局转换器:
[TemplatePart(Name = "Presenter", Type = typeof(ContentPresenter))]
[TemplatePart(Name = "TransformRoot", Type = typeof(Grid))]
public sealed class LayoutTransformer : ContentControl
{
public static readonly DependencyProperty LayoutTransformProperty = DependencyProperty.Register("LayoutTransform", typeof(Transform), typeof(LayoutTransformer), new PropertyMetadata(new PropertyChangedCallback(LayoutTransformer.LayoutTransformChanged)));
private Size _childActualSize = Size.Empty;
private const string TransformRootName = "TransformRoot";
private const string PresenterName = "Presenter";
private const double AcceptableDelta = 0.0001;
private const int DecimalsAfterRound = 4;
private Panel _transformRoot;
private ContentPresenter _contentPresenter;
private MatrixTransform _matrixTransform;
private Matrix _transformation;
public Transform LayoutTransform
{
get => (Transform)GetValue(LayoutTransformer.LayoutTransformProperty);
set => SetValue(LayoutTransformer.LayoutTransformProperty, (object)value);
}
private FrameworkElement Child => _contentPresenter?.Content as FrameworkElement ?? _contentPresenter;
public LayoutTransformer()
{
DefaultStyleKey = (object)typeof(LayoutTransformer);
IsTabStop = false;
UseLayoutRounding = false;
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
_transformRoot = (Panel)(GetTemplateChild(TransformRootName) as Grid);
_contentPresenter = GetTemplateChild(PresenterName) as ContentPresenter;
_matrixTransform = new MatrixTransform();
if (null != _transformRoot)
_transformRoot.RenderTransform = (Transform)_matrixTransform;
ApplyLayoutTransform();
}
private static void LayoutTransformChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
((LayoutTransformer)o).ProcessTransform((Transform)e.NewValue);
}
public void ApplyLayoutTransform()
{
ProcessTransform(LayoutTransform);
}
private void ProcessTransform(Transform transform)
{
_transformation = LayoutTransformer.RoundMatrix(GetTransformMatrix(transform), DecimalsAfterRound);
if (null != _matrixTransform)
_matrixTransform.Matrix = _transformation;
InvalidateMeasure();
}
private Matrix GetTransformMatrix(Transform transform)
{
if (null == transform) return Matrix.Identity;
if (transform is TransformGroup transformGroup)
{
var matrix1 = Matrix.Identity;
foreach (var transform1 in (TransformCollection)transformGroup.Children)
matrix1 = LayoutTransformer.MatrixMultiply(matrix1, GetTransformMatrix(transform1));
return matrix1;
}
if (transform is RotateTransform rotateTransform)
{
var num1 = 2.0 * Math.PI * rotateTransform.Angle / 360.0;
var m12 = Math.Sin(num1);
var num2 = Math.Cos(num1);
return new Matrix(num2, m12, -m12, num2, 0.0, 0.0);
}
if (transform is ScaleTransform scaleTransform)
return new Matrix(scaleTransform.ScaleX, 0.0, 0.0, scaleTransform.ScaleY, 0.0, 0.0);
if (transform is SkewTransform skewTransform)
{
var angleX = skewTransform.AngleX;
return new Matrix(1.0, 2.0 * Math.PI * skewTransform.AngleY / 360.0, 2.0 * Math.PI * angleX / 360.0, 1.0, 0.0, 0.0);
}
if (transform is MatrixTransform matrixTransform)
return matrixTransform.Matrix;
return Matrix.Identity;
}
protected override Size MeasureOverride(Size availableSize)
{
if (_transformRoot == null || null == Child)
return Size.Empty;
_transformRoot.Measure(!(_childActualSize == Size.Empty) ? _childActualSize : ComputeLargestTransformedSize(availableSize));
var x = 0.0;
var y = 0.0;
var desiredSize = _transformRoot.DesiredSize;
var width = desiredSize.Width;
desiredSize = _transformRoot.DesiredSize;
var height = desiredSize.Height;
var rect = LayoutTransformer.RectTransform(new Rect(x, y, width, height), _transformation);
return new Size(rect.Width, rect.Height);
}
protected override Size ArrangeOverride(Size finalSize)
{
var child = Child;
if (_transformRoot == null || null == child)
return finalSize;
var a = ComputeLargestTransformedSize(finalSize);
if (LayoutTransformer.IsSizeSmaller(a, _transformRoot.DesiredSize))
a = _transformRoot.DesiredSize;
var rect = LayoutTransformer.RectTransform(new Rect(0.0, 0.0, a.Width, a.Height), _transformation);
_transformRoot.Arrange(new Rect(-rect.Left + (finalSize.Width - rect.Width) / 2.0, -rect.Top + (finalSize.Height - rect.Height) / 2.0, a.Width, a.Height));
if (LayoutTransformer.IsSizeSmaller(a, child.RenderSize) && Size.Empty == _childActualSize)
{
_childActualSize = new Size(child.ActualWidth, child.ActualHeight);
InvalidateMeasure();
}
else
_childActualSize = Size.Empty;
return finalSize;
}
private Size ComputeLargestTransformedSize(Size arrangeBounds)
{
var size = Size.Empty;
var flag1 = double.IsInfinity(arrangeBounds.Width);
if (flag1)
arrangeBounds.Width = arrangeBounds.Height;
var flag2 = double.IsInfinity(arrangeBounds.Height);
if (flag2)
arrangeBounds.Height = arrangeBounds.Width;
var m11 = _transformation.M11;
var m12 = _transformation.M12;
var m21 = _transformation.M21;
var m22 = _transformation.M22;
var num1 = Math.Abs(arrangeBounds.Width / m11);
var num2 = Math.Abs(arrangeBounds.Width / m21);
var num3 = Math.Abs(arrangeBounds.Height / m12);
var num4 = Math.Abs(arrangeBounds.Height / m22);
var num5 = num1 / 2.0;
var num6 = num2 / 2.0;
var num7 = num3 / 2.0;
var num8 = num4 / 2.0;
var num9 = -(num2 / num1);
var num10 = -(num4 / num3);
if (0.0 == arrangeBounds.Width || 0.0 == arrangeBounds.Height)
size = new Size(arrangeBounds.Width, arrangeBounds.Height);
else if (flag1 && flag2)
size = new Size(double.PositiveInfinity, double.PositiveInfinity);
else if (!LayoutTransformer.MatrixHasInverse(_transformation))
size = new Size(0.0, 0.0);
else if (0.0 == m12 || 0.0 == m21)
{
var num11 = flag2 ? double.PositiveInfinity : num4;
var num12 = flag1 ? double.PositiveInfinity : num1;
if (0.0 == m12 && 0.0 == m21)
size = new Size(num12, num11);
else if (0.0 == m12)
{
var height = Math.Min(num6, num11);
size = new Size(num12 - Math.Abs(m21 * height / m11), height);
}
else if (0.0 == m21)
{
var width = Math.Min(num7, num12);
size = new Size(width, num11 - Math.Abs(m12 * width / m22));
}
}
else if (0.0 == m11 || 0.0 == m22)
{
var num11 = flag2 ? double.PositiveInfinity : num3;
var num12 = flag1 ? double.PositiveInfinity : num2;
if (0.0 == m11 && 0.0 == m22)
size = new Size(num11, num12);
else if (0.0 == m11)
{
var height = Math.Min(num8, num12);
size = new Size(num11 - Math.Abs(m22 * height / m12), height);
}
else if (0.0 == m22)
{
var width = Math.Min(num5, num11);
size = new Size(width, num12 - Math.Abs(m11 * width / m21));
}
}
else if (num6 <= num10 * num5 + num4)
size = new Size(num5, num6);
else if (num8 <= num9 * num7 + num2)
{
size = new Size(num7, num8);
}
else
{
var width = (num4 - num2) / (num9 - num10);
size = new Size(width, num9 * width + num2);
}
return size;
}
private static bool IsSizeSmaller(Size a, Size b)
{
return a.Width + AcceptableDelta < b.Width || a.Height + AcceptableDelta < b.Height;
}
private static Matrix RoundMatrix(Matrix matrix, int decimals)
{
return new Matrix(Math.Round(matrix.M11, decimals), Math.Round(matrix.M12, decimals), Math.Round(matrix.M21, decimals), Math.Round(matrix.M22, decimals), matrix.OffsetX, matrix.OffsetY);
}
private static Rect RectTransform(Rect rect, Matrix matrix)
{
var point1 = matrix.Transform(new Point(rect.Left, rect.Top));
var point2 = matrix.Transform(new Point(rect.Right, rect.Top));
var point3 = matrix.Transform(new Point(rect.Left, rect.Bottom));
var point4 = matrix.Transform(new Point(rect.Right, rect.Bottom));
var x = Math.Min(Math.Min(point1.X, point2.X), Math.Min(point3.X, point4.X));
var y = Math.Min(Math.Min(point1.Y, point2.Y), Math.Min(point3.Y, point4.Y));
var num1 = Math.Max(Math.Max(point1.X, point2.X), Math.Max(point3.X, point4.X));
var num2 = Math.Max(Math.Max(point1.Y, point2.Y), Math.Max(point3.Y, point4.Y));
return new Rect(x, y, num1 - x, num2 - y);
}
private static Matrix MatrixMultiply(Matrix matrix1, Matrix matrix2)
{
return new Matrix(matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21, matrix1.M11 * matrix2.M12 + matrix1.M12 * matrix2.M22, matrix1.M21 * matrix2.M11 + matrix1.M22 * matrix2.M21, matrix1.M21 * matrix2.M12 + matrix1.M22 * matrix2.M22, matrix1.OffsetX * matrix2.M11 + matrix1.OffsetY * matrix2.M21 + matrix2.OffsetX, matrix1.OffsetX * matrix2.M12 + matrix1.OffsetY * matrix2.M22 + matrix2.OffsetY);
}
private static bool MatrixHasInverse(Matrix matrix)
{
return 0.0 != matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21;
}
}
<Style TargetType="local:LayoutTransformer">
<Setter Property="Foreground" Value="#FF000000" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LayoutTransformer">
<Grid x:Name="TransformRoot" Background="{TemplateBinding Background}">
<ContentPresenter x:Name="Presenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
调解员:
public class DoubleAnimationMediator : FrameworkElement
{
private string _layoutTransformerName;
public LayoutTransformer LayoutTransformer { get; set; }
public string LayoutTransformerName
{
get => _layoutTransformerName;
set
{
_layoutTransformerName = value;
LayoutTransformer = null;
}
}
public static readonly DependencyProperty AnimationValueProperty =
DependencyProperty.Register(
"AnimationValue",
typeof(double),
typeof(DoubleAnimationMediator),
new PropertyMetadata(0, AnimationValuePropertyChanged));
private static void AnimationValuePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
{
((DoubleAnimationMediator)o).AnimationValuePropertyChanged();
}
public double AnimationValue
{
get => (double)GetValue(AnimationValueProperty);
set => SetValue(AnimationValueProperty, value);
}
private void AnimationValuePropertyChanged()
{
if (null == LayoutTransformer)
{
LayoutTransformer = FindName(LayoutTransformerName) as LayoutTransformer;
if (null == LayoutTransformer)
{
throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
"AnimationMediator was unable to find a LayoutTransformer named \"{0}\".",
LayoutTransformerName));
}
}
CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => LayoutTransformer.ApplyLayoutTransform()).AsTask().ConfigureAwait(true);
}
}
测试控件:
public class TestControl : Control
{
public TestControl()
{
DefaultStyleKey = typeof(TestControl);
PointerEntered += OnPointerEntered;
PointerExited += OnPointerExited;
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
VisualStateManager.GoToState(this, "Minimized", false);
}
private void OnPointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Minimized", false);
}
private void OnPointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
{
VisualStateManager.GoToState(this, "Maximized", false);
}
}
<Style TargetType="local:TestControl">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:TestControl">
<Grid VerticalAlignment="{TemplateBinding VerticalAlignment}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="DisplayStates">
<VisualState x:Name="Minimized">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="scaleYMediator"
Storyboard.TargetProperty="AnimationValue"
EnableDependentAnimation="True"
Duration="0:0:0.2"
To="0"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Maximized">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="scaleYMediator"
Storyboard.TargetProperty="AnimationValue"
EnableDependentAnimation="True"
Duration="0:0:0.2"
To="1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<local:DoubleAnimationMediator x:Name="scaleYMediator"
LayoutTransformerName="layoutTransform"
AnimationValue="{Binding ScaleY, ElementName=scaleTransform, Mode=TwoWay}"/>
<Grid Background="Red"
Grid.Row="0">
<TextBlock Text="Header"/>
</Grid>
<local:LayoutTransformer x:Name="layoutTransform" Grid.Row="1"
Background="Orange">
<local:LayoutTransformer.LayoutTransform>
<TransformGroup>
<ScaleTransform x:Name="scaleTransform" ScaleY="0"/>
</TransformGroup>
</local:LayoutTransformer.LayoutTransform>
<local:LayoutTransformer.Content>
<Grid>
<TextBlock Text="Content"/>
</Grid>
</local:LayoutTransformer.Content>
</local:LayoutTransformer>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
关于UWP 网格行高在内容缩放变换后不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51668711/
我正在寻找一种简单的解决方案来将对象从一个地方移动和缩放到另一个地方。 我做了一个JSfiddle用这个代码。问题是我需要它在某个时刻停止变小。所以它有一个最小尺寸,另一个问题是我希望它既缩小又向左移
我正在尝试通过沿 x 轴上下翻转(180 度)来为悬停时的图像设置动画。 就像here 除非我出于某种原因无法让它工作。 img { transition:all 2s ease-in-out
我想实例化一个 slider 约束,它允许 body 在 A 点和 B 点之间滑动。 为了实例化约束,我指定了两个物体进行约束,在这种情况下,一个动态物体被约束到静态世界,比如滑动门。 第三个和第四个
我想使用此功能旋转然后停止在特定点或角度。现在该元素只是旋转而不停止。代码如下: $(function() { var $elie = $("#bkgimg");
我正在尝试使用 CATransform3D 向 View 添加透视图。目前,这就是我得到的: 这就是我想要得到的: 我很难做到这一点。我完全迷失在这里。这是我的代码: CATransform3D t
我编写了一个图形用户界面,用户可以在其中在 (640x480) 窗口中绘制内容。它使该绘图成为一组存储在 Vector 数组中的点。 现在,我如何将这些点集平移到原点(0,0 窗口左上角)或将其放在指
我的应用程序中有两张图像相互叠加,分别表示为 foreground 和 background。对于这两个,我都使用 background-attachment: fixed 来确保图像始终彼此完全相同
如何在不损失质量的情况下应用旋转变换?我试过添加 translateZ(0) 但它无济于事。这是例子: svg { background-color: rgb(93, 193, 93); }
我有一个 div,我试图在悬停时缩放它(只是 Y)。问题是它在没有过渡的情况下运行良好。当我使用过渡时,div 在顶部缩放一点然后下降,检查 fiddle 。问题是如何防止 div 那样缩放?我希望它
我正在尝试使用 transform: scale 图像网格 http://movies.themodern-nerd.com/genre .从左向右滚动时它工作正常,悬停的图像将停留在其他图像之上,但
我正在查看 CSS3 Transform 并且想要一个既倾斜又旋转的盒子。 我试过使用: transform:rotate(80deg); -moz-transform:rotate(80deg);
当用户在图像父元素上执行 mousemove 时,我试图在 img 上添加平滑移动效果(此处为 .carousel-img)但我无法正常运行它。 我做错了什么? $('.carousel-img').
我有 div 元素在其他 div 元素中垂直对齐。 我使用以下方法对齐它们:position: relative;变换:翻译Y(-50%);顶部:50%。这很好用。 我现在想缩放元素(使用 jQuer
我在这个 fiddle 中使用 RotateX 后创建了 3D 效果: http://jsfiddle.net/vEWEL/11/ 但是,我不确定如何在这个 Fiddle 中的红色方 block 上实
使用 transform: scale(x.x) 而不是使用 width 和 height 属性进行传统的调整大小有什么缺点吗?缩放会产生质量较低的图像或其他什么吗? 最佳答案 Scale 生成总体上
我在一个点上有一个对象,比如相对于原点的 x、y、z。 我想对点应用一些变换,比如旋转和平移,并在变换后的点渲染对象。我正在使用 glTranslatef() 和 glRotatef() 函数。它看起
有没有办法将转换应用到插入了 :before 的元素上? 以下方法无效,但我愿意接受其他解决方案。 .itemclass:before { content: "➨"; transform:
我找到了这个:width/height after transform 和其他几个,但没有什么不是我正在寻找的。我想要的是将某些东西缩放到其大小的 50%(当然还有漂亮的动画过渡)并让页面布局重新调整
我想使用变换为元素位置设置动画。我怎么能在这个翻译中添加一些曲线(没什么特别的,只是不是一条完整的直线)?对于 jquery,我会使用效果很好的 easeInSine。 var a = documen
我试着写一个 TransformMesh功能。该函数接受一个 Mesh对象和 Matrix目的。这个想法是使用矩阵来转换网格。为此,我锁定了顶点缓冲区,并在每个顶点上调用了 Vector3::Tran
我是一名优秀的程序员,十分优秀!