Hey all,
I made a sidebar that slides in and out.
I done this with a timer.
The touchview comes into the play when the sidebar is in view, and I'm detecting touches on there so i can move the sidebar out when I touched outside the sidebar.
This works great, I love it! However, after moving to an other viewcontroller and going back to the main.
The sidebar still works, it opens, closes, and then it won't open anymore because when I closed it after I came back to the view, it seems that my timer wont get invalidated. (I putted an log inside the if statement, when counter meets its end, and it keeps sending that log)
This is how Im calling my timer.
setting isAnimating just makes the app be sure that the sidebar wont start bouncing for ever
(for the people with a trigger finger ;-) )
It works like a charm untill I moved to an other viewcontroller and came back.
My viewDidAppear contains this:
I really really can't see the fault. Anyone else does ?? I could really need a help here.
-----
Forgot to mention I'm using an swipe gesture on the naviView and a touchesBegan on the touchView.
Huge improvement: UIView animationWithDuration:animation
Fix: Properly delegate my gestures.
I made a sidebar that slides in and out.
I done this with a timer.
Code:
-(void)moveViews {
counter++;
if(!inNavi) {
if(slideOver)
[mainView setFrame: CGRectMake(mainView.frame.origin.x - 5, mainView.frame.origin.y, mainView.frame.size.width, mainView.frame.size.height)];
[naviView setFrame: CGRectMake(naviView.frame.origin.x - 5, naviView.frame.origin.y, naviView.frame.size.width, naviView.frame.size.height)];
} else {
if(slideOver)
[mainView setFrame: CGRectMake(mainView.frame.origin.x + 5, mainView.frame.origin.y, mainView.frame.size.width, mainView.frame.size.height)];
[naviView setFrame: CGRectMake(naviView.frame.origin.x + 5, naviView.frame.origin.y, naviView.frame.size.width, naviView.frame.size.height)];
}
if(counter == (int)(naviView.frame.size.width / 5)) {
if(inNavi) {
inNavi = NO;
[naviView setFrame: CGRectMake(mainView.frame.size.width, naviView.frame.origin.y, naviView.frame.size.width, naviView.frame.size.height)];
[touchView setFrame: CGRectMake(mainView.frame.size.width, touchView.frame.origin.y, touchView.frame.size.width, touchView.frame.size.height)];
} else {
inNavi = YES;
[touchView setFrame: CGRectMake(0, touchView.frame.origin.y, touchView.frame.size.width, touchView.frame.size.height)];
}
[openNaviButtons invalidate];
openNaviButtons = nil;
isAnimating = NO;
counter = 0;
}
}
The touchview comes into the play when the sidebar is in view, and I'm detecting touches on there so i can move the sidebar out when I touched outside the sidebar.
This works great, I love it! However, after moving to an other viewcontroller and going back to the main.
The sidebar still works, it opens, closes, and then it won't open anymore because when I closed it after I came back to the view, it seems that my timer wont get invalidated. (I putted an log inside the if statement, when counter meets its end, and it keeps sending that log)
This is how Im calling my timer.
Code:
-(IBAction)openButtons:(id)sender {
if(!inNavi && !isAnimating) {
isAnimating = YES;
openNaviButtons = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(moveViews) userInfo:nil repeats: YES];
}
}
-(IBAction)closeButtons:(id)sender {
if(inNavi && !isAnimating) {
isAnimating = YES;
openNaviButtons = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(moveViews) userInfo:nil repeats: YES];
}
}
setting isAnimating just makes the app be sure that the sidebar wont start bouncing for ever
(for the people with a trigger finger ;-) )
It works like a charm untill I moved to an other viewcontroller and came back.
My viewDidAppear contains this:
Code:
[naviView setFrame: CGRectMake(mainView.frame.size.width, naviView.frame.origin.y, naviView.frame.size.width, naviView.frame.size.height)];
isAnimating = NO;
inNavi = NO;
counter = 0; //Forgot to mention this one.
I really really can't see the fault. Anyone else does ?? I could really need a help here.
-----
Forgot to mention I'm using an swipe gesture on the naviView and a touchesBegan on the touchView.
Huge improvement: UIView animationWithDuration:animation
Fix: Properly delegate my gestures.
Last edited: