我尝试打开两个 subview 并及时关闭,所以我这样尝试
- (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);
}
];
}
我需要两个 View 改变位置然后到达相同的位置,但是当我调用这两种方法时打开速度慢但关闭速度非常快。
关闭 View 时如何设置计时器?
最佳答案
你的结尾部分;
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);
不在动画 block 内。打开的持续时间为 2.8 秒,但关闭将在没有任何持续时间的情况下执行。
将结束部分放在另一个动画 block 中。
[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){
}];
关于ios - 关闭 subview 时如何设置计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26335555/