none
如何实现按住屏幕,使一个矩形旋转 RRS feed

  • 问题

  • 如何按住屏幕,使屏幕上的矩形旋转,离开屏幕,矩形停止旋转?而且不回复初始样子

    用什么方法???

    请大神指教,谢谢

    • 已编辑 崔東 2014年12月13日 7:14
    2014年12月13日 4:34

答案

  • 已经解决

    <Canvas Name="ceshi" Grid.Row="1" Background="Black" PointerPressed="Canvas_PointerPressed" PointerReleased="Canvas_PointerReleased" Width="400" PointerEntered="Canvas_PointerEntered" >


                <Ellipse  Height="15" Canvas.Left="140" Stroke="Black" Canvas.Top="394" Width="15" Fill="#FFF50909" RenderTransformOrigin="3.934,0.612">
                    <Ellipse.RenderTransform >
                        <RotateTransform x:Name="ceshi_1"/>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse  Fill="#FF09A2F9" Height="15" Canvas.Left="245" Stroke="Black" Canvas.Top="394" Width="15" RenderTransformOrigin="-3.066,0.695">
                    <Ellipse.RenderTransform >
                        <RotateTransform x:Name="ceshi_2"/>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Canvas.Resources >
                    <Storyboard x:Name="storyboard_1">
                        <DoubleAnimation To="720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_1"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                        <DoubleAnimation To="720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_2"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                       
                       
                       
                    </Storyboard>
                    <Storyboard x:Name="storyboard_2">
                        <DoubleAnimation To="-720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_1"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                        <DoubleAnimation To="-720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_2"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>

                    </Storyboard>


                </Canvas.Resources>

            </Canvas>

    后台

    private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                if (point .X >200)
                storyboard_1.Begin();
                else
                    storyboard_2.Begin();
             
               
            }

            private void Canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
            {
               
                if (point.X > 200)
                    storyboard_1.Pause();
                else
                    storyboard_2.Pause();
                   
               
               
               
               
              
            }
            Point point = new Point();
            private void Canvas_PointerEntered(object sender, PointerRoutedEventArgs e)
            {
                point = e.GetCurrentPoint(ceshi).Position;
            }

    谁有更好的办法请通知我 谢谢

    • 已标记为答案 崔東 2014年12月13日 9:07
    • 已编辑 崔東 2014年12月13日 9:08
    2014年12月13日 9:07

全部回复

  • 已经解决

    <Canvas Name="ceshi" Grid.Row="1" Background="Black" PointerPressed="Canvas_PointerPressed" PointerReleased="Canvas_PointerReleased" Width="400" PointerEntered="Canvas_PointerEntered" >


                <Ellipse  Height="15" Canvas.Left="140" Stroke="Black" Canvas.Top="394" Width="15" Fill="#FFF50909" RenderTransformOrigin="3.934,0.612">
                    <Ellipse.RenderTransform >
                        <RotateTransform x:Name="ceshi_1"/>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Ellipse  Fill="#FF09A2F9" Height="15" Canvas.Left="245" Stroke="Black" Canvas.Top="394" Width="15" RenderTransformOrigin="-3.066,0.695">
                    <Ellipse.RenderTransform >
                        <RotateTransform x:Name="ceshi_2"/>
                    </Ellipse.RenderTransform>
                </Ellipse>
                <Canvas.Resources >
                    <Storyboard x:Name="storyboard_1">
                        <DoubleAnimation To="720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_1"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                        <DoubleAnimation To="720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_2"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                       
                       
                       
                    </Storyboard>
                    <Storyboard x:Name="storyboard_2">
                        <DoubleAnimation To="-720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_1"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>
                        <DoubleAnimation To="-720"
                                         EnableDependentAnimation="True"
                                         AutoReverse="False"
                                         RepeatBehavior="Forever"
                                         Duration=" 0:0:3"
                                         Storyboard.TargetName="ceshi_2"
                                         Storyboard.TargetProperty="Angle">
                        </DoubleAnimation>

                    </Storyboard>


                </Canvas.Resources>

            </Canvas>

    后台

    private void Canvas_PointerPressed(object sender, PointerRoutedEventArgs e)
            {
                if (point .X >200)
                storyboard_1.Begin();
                else
                    storyboard_2.Begin();
             
               
            }

            private void Canvas_PointerReleased(object sender, PointerRoutedEventArgs e)
            {
               
                if (point.X > 200)
                    storyboard_1.Pause();
                else
                    storyboard_2.Pause();
                   
               
               
               
               
              
            }
            Point point = new Point();
            private void Canvas_PointerEntered(object sender, PointerRoutedEventArgs e)
            {
                point = e.GetCurrentPoint(ceshi).Position;
            }

    谁有更好的办法请通知我 谢谢

    • 已标记为答案 崔東 2014年12月13日 9:07
    • 已编辑 崔東 2014年12月13日 9:08
    2014年12月13日 9:07
  • 很高兴你的问题解决了,RotateTransform 是我们常用的实现方式

    这里还有一篇Rob的文章,英语还可以的话可以参考:http://blogs.msdn.com/b/wsdevsol/archive/2014/06/10/constraining-manipulations.aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2014年12月15日 6:53
    版主
  • 楼主Nice, 版主威武!
    2014年12月15日 8:12