【问题标题】:how to set timer when closed subviews关闭子视图时如何设置计时器
【发布时间】:2014-12-07 18:08:58
【问题描述】:

我试图打开两个子视图并在时间关闭所以我尝试这样

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if(event.type == UIEventSubtypeMotionShake)
    {
        [self shakeView];
        //[self open];
    }
}

-(void)shakeView
{
    [UIView animateWithDuration:2.8
                     animations:^{
                         //OPEN
                         firstView.frame = CGRectMake(0, -40, self.view.frame.size.width, self.view.frame.size.height/2);
                         secondView.frame = CGRectMake(0, 260, self.view.frame.size.width, self.view.frame.size.height/2);

                         // Its final location
                     }
                     completion:^(BOOL finished) {
                         // Closed 
                         firstView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
                         secondView.frame = CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
                     }
    ];
}

我需要两个视图改变的位置,然后到达相同的位置,但是当我调用这两个方法时,打开速度很慢,但关闭速度很快。

所以请任何人帮助我,关闭视图时如何设置计时器

感谢高级版。

【问题讨论】:

    标签: ios objective-c uiview uiviewanimation handshake


    【解决方案1】:

    你的结束部分;

    firstView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
    
    secondView.frame=CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
    

    不在动画块内。打开的持续时间为 2.8 秒,但关闭将在没有任何持续时间的情况下执行。

    将你的关闭部分放在另一个动画块中。

    [UIView animateWithDuration:0.4 animations:^{
        firstView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
    
        secondView.frame=CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
         }completion:^(BOOL finished){
         }];
    

    希望这会有所帮助.. :)

    【讨论】:

    • 感谢回复请告诉我如何设置计时器关闭部分持续时间
    • @user3678584> 将您关闭的部分放在动画块内。
    【解决方案2】:

    试试这个。

    -(void)shakeView
    {
    [UIView animateWithDuration:2.8
                     animations:^{
                         //OPEN
                         firstView.frame =CGRectMake(0, -40, self.view.frame.size.width, self.view.frame.size.height/2);
                         secondView.frame =CGRectMake(0, 260, self.view.frame.size.width, self.view.frame.size.height/2);
                         // its final location
                     }
                     completion:^(BOOL finished)
     {
         //Closed
    
         [UIView animateWithDuration:0.5 animations:^{
    
             firstView.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/2);
             secondView.frame=CGRectMake(0,230 , self.view.frame.size.width, self.view.frame.size.height/2);
         }];
    
     }];}
    

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 2015-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 2015-10-18
      • 1970-01-01
      相关资源
      最近更新 更多