问题描述
所以有一个 UITextField
并且我在字段上有字符限制.如果用户尝试输入更大的内容,UIView
就会出现.我已经把那部分动画化了.这是我所拥有的:
So there is a UITextField
and I have a limit of characters on the field. If user tries to enter anything bigger, UIView
appears. I already have that part animated. Here is what I have:
public void animateHoursMesg() {
var HoursMesgExpandPos = new PointF (248.0f, 273.0f);
var HoursMesgInitPos = new PointF (400.0f, 273.0f);
UIView.Animate (
duration: 0.3f,
delay: 0,
options: UIViewAnimationOptions.CurveEaseInOut,
animation: () => {
if (Flag_HoursMesg) {
view_HoursLimitMesg.Center = HoursMesgInitPos;
Flag_HoursMesg = false;
} else {
view_HoursLimitMesg.Center = HoursMesgExpandPos;
Flag_HoursMesg = true;
}
},
completion: () => {
}
);
}
问题是我希望这个视图在出现 5 秒后动画化.
The problem is I want this view to animate away 5 seconds after it appears.
有人可以帮我解决这个问题吗?
Can someone please help me with this?
感谢您的宝贵时间.
推荐答案
在 animate 方法的完成块中,使用 NSTimer 安排一个块从那时起执行 5 秒.
In your completion block on the animate method, use an NSTimer to schedule a block to execute 5 seconds from then.
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(animateAway)
userInfo:nil
repeats:NO];
然后为 animateAway
创建另一个方法来反转您之前的动画.
Then just create another method for the animateAway
that reverses your previous animation.
这篇关于UIView 在 Timer 上设置动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!