我想创建一个动画菜单。IOS - 动画没有响应
- 第一它是隐藏的外屏
- 当用户点击屏幕,它将在
- 用户滑动可以点击它,它做一些三分球后
- 那么它会滑动屏幕之外
但问题是,当我点击它时没有反应。为什么?
示例代码:所有代码都在我的UIView类中。
showing = NO;
box = [[UIView alloc] initWithFrame:CGRectMake(500,-200,200,200)];
box.backgroundColor = [UIColor redColor];
UITapGestureRecognizer *tapBox = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapMenuHandler:)] autorelease];
[box addGestureRecognizer:tapBox];
[self addSubView:box];
和:
-(void) tapMenuHandler: (UIView *)obj {
//Do something
NSLog(@"tap box");
}
和:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (!showing) {
box.frame = CGRectMake(500, -200, 200, 200);
[UIView animateWithDuration:0.5f delay:0.3f options:(UIViewAnimationOptionAllowUserInteraction) animations:^{
box.frame = CGRectMake(500, 200, 200, 200);
} completion:^(BOOL finished) {
showing = YES;
[UIView animateWithDuration:0.5f delay:3.0f options:(UIViewAnimationOptionAllowUserInteraction) animations:^{
box.frame = CGRectMake(500, -200, 200,200);
} completion:^(BOOL finished) {
showing = NO;
}];
}];
}
}
感谢您的帮助,我的英语水平:)对不起
编辑:更详细 我三编辑设置开始我的方块在屏幕上的起源(前。 500,600),即使我的箱子移动到另一个位置,仍然总是在起点(500,600)处轻敲。
更新: 我改变了我的方式,通过使用NSTimer移动框外屏,然后它的工作!
[UIView animateWithDuration:0.5f delay:0.3f options:UIViewAnimationOptionAllowUserInteraction animations:^{
box.frame = CGRectMake(500,200,200,200);
} completion:^(BOOL finished) {
isShowMenubar = YES;
//use NSTimer instead of delay
[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(hideBox) userInfo:nil repeats:NO];
}];
和
-(void)hideBox {
[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionAllowUserInteraction animations:^{
box.frame = CGRectMake(500,-200,200,200);} completion:^(BOOL finished) {
isShowMenubar = NO;
}];
}
你实现tapMenuHandler法您为TapGestureRecognizer设置? – matzino 2012-03-22 15:27:49
感谢matzino :)这是我的错。我编辑我的代码,但它仍然是问题。 – navinking2000 2012-03-22 16:44:24
您的tapMenuHandler-Method有一个错误的签名。它必须像 - (IBAction)tapMenuHandler:(UIGestureRecognizer *)发件人。 IBAction或void是相等的,但发送者参数必须是您的UIGestureRecognizer。解决你的问题? – matzino 2012-03-23 10:05:16