アニメーションメニューを作成したいと思います。最初のユーザが画面をタップしたとき、それはユーザーがそれをタップすることができ、それが何か IOS - アニメーションが応答しない
- その後、3S後にそれが画面外
しかし、問題はそれをタップしたときの応答ではありません。どうして?
サンプルコード:すべてのコードは、私の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;
}];
}
を助け
希望すべきですか? – matzino
マッツィーノに感謝します:)それは私の間違いです。私は自分のコードを編集しますが、それでも問題はあります。 – navinking2000
あなたのtapMenuHandler-Methodの署名が間違っています。それは - (IBAction)tapMenuHandler:(UIGestureRecognizer *)のようなものでなければなりません。 IBActionまたはvoidは同じですが、送信者のパラメータはUIGestureRecognizerでなければなりません。あなたの問題を解決しますか? – matzino