【发布时间】:2012-06-07 18:58:27
【问题描述】:
我有一个视图,例如带有一些按钮的快捷方式视图。现在,当我单击快捷方式按钮时,会出现快捷方式视图,我希望用户不触摸视图,如何在 8 秒后隐藏快捷方式视图,并且用户在 8 秒前触摸视图,它将出现。
【问题讨论】:
我有一个视图,例如带有一些按钮的快捷方式视图。现在,当我单击快捷方式按钮时,会出现快捷方式视图,我希望用户不触摸视图,如何在 8 秒后隐藏快捷方式视图,并且用户在 8 秒前触摸视图,它将出现。
【问题讨论】:
您可以使用 UIView 动画并将视图移出屏幕
[UIView animateWithDuration:0.333f
delay:8.0f
options:UIViewAnimationCurveEaseOut
animations:^(void) {
myView.transform = CGAffineTransformMakeTranslation(0,self.view.frame.size.height);
}
completion:nil];
在此示例中,我将您的视图移动到屏幕底部,CGAffineTransformMakeTranslation(x,y) 将您的视图框架移动给定的 x 和 y 点
然后把它移回来,好吧,你明白了;)
【讨论】:
您可以使用- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay 和+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget 方法
-(void)showShortcuts
{
// all the code you need to show your shortcuts view
...
[self perfornSelector:@selector(hideShortcuts) withObject:nil afterDelay:8.0];
}
-(void)hideShortcuts
{
// all the code you need to hide your shortcuts view
...
}
-(void)shortcutPressed:(id) shortcut
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
// code your shortcut is supposed to trigger
...
}
【讨论】: