ios 关闭子视图时如何设置计时器

kqlmhetl  于 2023-01-27  发布在  iOS
关注(0)|答案(2)|浏览(160)

我试着打开两个子视图,但同时又关闭了,所以我试着这样做

- (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);
                     }
    ];
}

我需要两个视图改变立场,然后来到相同的立场,但当我调用这两个方法打开缓慢,但关闭非常快。
关闭视图时如何设置计时器?

sdnqo3pr

sdnqo3pr1#

你的结尾部分;

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){
     }];
v9tzhpje

v9tzhpje2#

试试这个。

-(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);
     }];

 }];}

相关问题