Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 27    Views: 199

Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
12/16/12 05:40 AM (11 years ago)

Easy swipe back and next

Ok guys a few people have asked how to integrate swipe gestures into there apps, you can do this by adding the following code into whatever screens you want the swipes to work in. This works by utilising the commands navLeftTap and navRightTap For this to work, you need to add the screen under right button load screen in the control panel of the screen you want to swipe right too. Swiping left will automatically go back. (you can add a load next screen without having the button show). So the code Insert the following code under view did load UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)]; [swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; [self.view addGestureRecognizer:swipeLeft]; UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe:)]; [swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; [self.view addGestureRecognizer:swipeRight]; Then add the following two methods anywhere make sure they aren't in anywhere else curly braces. - (IBAction)leftSwipe:(id)sender { [self navLeftTap]; } - (IBAction)rightSwipe:(id)sender { [self navRightTap]; } That's it. Happy swiping If you want the swipes to do anything else modify the methods, see the tutorial for button do anything to modify the code.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 09:04 AM (11 years ago)
Thanks Kittsy!
 
StaleysGirl
Aspiring developer
Profile
Posts: 56
Reg: Jul 02, 2012
San Diego
4,260
like
12/16/12 09:10 AM (11 years ago)
Awesome, thanks Kittsy!
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 10:46 AM (11 years ago)
I want to use the swipe gesture for a blank screen and when I input the code into the bt_screen_blank.m file under viewdidload I get about 6 errors.. Am I pasting it in the wrong place?
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 10:58 AM (11 years ago)
I want to use the swipe gesture for a blank screen and when I input the code into the bt_screen_blank.m file under viewdidload I get about 6 errors.. Am I pasting it in the wrong place?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 11:29 AM (11 years ago)
The first pieces of code go into the view did load. The second two go anywhere asking as they're not within the curly braces of other methods. Description of errors and maybe a screenshot would be helpful to diagnose your problem
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 11:36 AM (11 years ago)
I just realised that all this time I had been pasting the code in the wrong place and I corrected it. It's working good now. Thank you
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 11:43 AM (11 years ago)
No probs Happy swiping
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 11:46 AM (11 years ago)
Thank you, and just a quick one, how would I customize the code to use a tap gesture to go back instead of a swipe? It would be appreciated if you could post the code in the reply. Thank you
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 12:03 PM (11 years ago)
I'm not by a computer but I wouldn't advise that gesture. You should use swipe gestures or button taps. Imagine if you just tapped a page and you went backwards unknowingly.
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 12:25 PM (11 years ago)
I get it. It is true, but I just ran through the thought of the end user not knowing that the have to swipe to return because there is no back button or arrows etc.
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 12:27 PM (11 years ago)
Technically with buzztouch there will always be a back button. Unless you hide the mac bar. If you hide the nab bar ios common practice is swipe to navigate
 
armacfan
Apple Fan
Profile
Posts: 157
Reg: Sep 05, 2011
location unknow...
3,520
like
12/16/12 12:37 PM (11 years ago)
I guess so. Thank you for your time and help. It's appreciated.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 01:26 PM (11 years ago)
How might I use this from a menu screen to swipe to the next home-screen tab? I have the following code as an example: ********************************* - (IBAction)leftSwipe:(id)sender { //appDelegate MyAppName_appDelegate *appDelegate = (MyAppName_appDelegate *)[[UIApplication sharedApplication] delegate]; BT_item *screenObjectToLoad = nil; NSString *homeScreenID = @"HomeScreenID1"; screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:homeScreenID]; if(screenObjectToLoad != nil){ [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:thisMenuItem:screenObjectToLoad]; }else{ //show message [BT_debugger showIt:self:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this click?")]]; } } ********************************* Ideally what I'd like to do is load the itemID's for each tab into an array and use the swipe method you described to go backward or forward in the tabs. In this example above, I'm starting with the basic method of going to a particular tab (in this case, "HomeScreenID1"). However, it doesn't know what to use for "thisMenuItem", since it's not being activated on a menu-item select. Any advice?
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 01:38 PM (11 years ago)
Alright guys a word of warning when I said I wasn't by a computer before. What I meant to say is I'm out on the ale/booze/devil juice. Any advice I give may be wrong but. From that code just give the nick bane or I'd of your home screen and yes that will work. Will gave a look when sober.
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 01:49 PM (11 years ago)
Thanks-worked perfectly!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 01:59 PM (11 years ago)
Ha ha pissed and still giving out advice merry swipeness
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 03:42 PM (11 years ago)
Careful now-don't kill off too many of those brain cells... the rest of us are counting on them! ;)
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
12/16/12 04:00 PM (11 years ago)
Chris, Where are you inserting the second set of code? - (IBAction)leftSwipe:(id)sender { [self navLeftTap]; } - (IBAction)rightSwipe:(id)sender { [self navRightTap]; }
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
12/16/12 04:04 PM (11 years ago)
Rad roc as long as they aren't in any others curly braces anywhere. Just smashed don't stop believing on the karaoke, so you lot don't stop believing
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
12/16/12 04:06 PM (11 years ago)
lmbo.....
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 04:07 PM (11 years ago)
I have it outside of curlies...working well. Just need to write code for tab array now. But gotta go back to church/work for now
 
Rad Doc
Apple Fan
Profile
Posts: 653
Reg: Oct 08, 2010
USA, NYC
8,580
like
12/16/12 04:10 PM (11 years ago)
Got it my good friend. PARTY ON!!
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 09:32 PM (11 years ago)
Okay, I've gotten a bit farther in my goal to swipe to change tabs. But, I'm a little stuck. Here's what I've gotten so far: ********************************** - (IBAction)rightSwipe:(id)sender { [BT_debugger showIt:self:@"right swipe activated"]; //appDelegate FUMCBixby_appDelegate *appDelegate = (FUMCBixby_appDelegate *)[[UIApplication sharedApplication] delegate]; //get total number of tabs int tabCt = 0; int tabCount = [[NSNumber numberWithInteger:[appDelegate.rootApp.tabs count]] intValue]; BT_item *thisScreen = nil; thisScreen = self.screenData; NSString *thisScreenID = thisScreen.itemId; while (tabCt < tabCount){ BT_item *screenObjectToLoad = nil; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:tabCt]; NSString *lastTabPointsTo = [BT_strings getJsonPropertyValue:screenObjectToLoad.jsonVars:@"homeScreenItemId":@""]; [BT_debugger showIt:self:@"checking IDs"]; [BT_debugger showIt:self:thisScreenID]; [BT_debugger showIt:self:lastTabPointsTo]; //if current tab == indexed tab if (thisScreenID == lastTabPointsTo) { int loadCt = 0; if (tabCt == 0) {loadCt = tabCount;[BT_debugger showIt:self:@"selecting last tab"];} else {loadCt = tabCt - 1;[BT_debugger showIt:self:@"selecting next tab"];} [BT_debugger showIt:self:@"found a match!"]; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:loadCt]; if(screenObjectToLoad != nil){ [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:screenObjectToLoad:screenObjectToLoad]; }else{ //show message [BT_debugger showIt:self:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this click?")]]; } } tabCt ++; }; } ********************************** Two problems: 1) The if statement never gets triggered. Even though I can verify in debugger that my two variables "thisScreenID" and "lastTabPointsTo" have the same value, the script passes right over the if clause. Any ideas? 2) When I was monkeying with the code I started out by getting it to swipe to a different tab by using a hard-coded index object like so: screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:1]; However, it would load the screen but did not show the tab bar at the bottom. What did I do wrong? Thanks! Chris
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 09:43 PM (11 years ago)
Okay - solved the first problem, and got a little more detail on the second. It's not that the tab bar goes away per se. If I'm going from one menu screen to another, then it remains, but the highlighted tab doesn't change. But if I go from a menu screen to a non-menu screen (one of my tabs is a html plugin screen), then the tab bar goes away. Here's my updated code: - (IBAction)rightSwipe:(id)sender { [BT_debugger showIt:self:@"right swipe activated"]; //appDelegate FUMCBixby_appDelegate *appDelegate = (FUMCBixby_appDelegate *)[[UIApplication sharedApplication] delegate]; //get total number of tabs int tabCt = 0; int tabCount = [[NSNumber numberWithInteger:[appDelegate.rootApp.tabs count]] intValue]; BT_item *thisScreen = nil; thisScreen = self.screenData; NSString *thisScreenID = thisScreen.itemId; while (tabCt < tabCount){ BT_item *screenObjectToLoad = nil; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:tabCt]; NSString *lastTabPointsTo = [BT_strings getJsonPropertyValue:screenObjectToLoad.jsonVars:@"homeScreenItemId":@""]; [BT_debugger showIt:self:@"checking IDs"]; [BT_debugger showIt:self:thisScreenID]; [BT_debugger showIt:self:lastTabPointsTo]; //if current tab == indexed tab if ([thisScreenID isEqualToString:lastTabPointsTo]) { int loadCt = 0; if (tabCt == 0) {loadCt = tabCount - 1;[BT_debugger showIt:self:@"selecting last tab"];} else {loadCt = tabCt - 1;[BT_debugger showIt:self:@"selecting next tab"];} [BT_debugger showIt:self:@"found a match!"]; screenObjectToLoad = [appDelegate.rootApp.tabs objectAtIndex:loadCt]; NSString *getTabID = [BT_strings getJsonPropertyValue:screenObjectToLoad.jsonVars:@"homeScreenItemId":@""]; screenObjectToLoad = [appDelegate.rootApp getScreenDataByItemId:getTabID]; if(screenObjectToLoad != nil){ [BT_viewControllerManager handleTapToLoadScreen:[self screenData]:screenObjectToLoad:screenObjectToLoad]; }else{ //show message [BT_debugger showIt:self:[NSString stringWithFormat:@"%@",NSLocalizedString(@"menuTapError",@"The application doesn't know how to handle this click?")]]; } } tabCt ++; }; }
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
12/16/12 09:54 PM (11 years ago)
I did notice on my debugger output that after the new screen is loaded via swipe that the while statement kept on going through the loop. Could that be causing the issue with the tab bar for some reason?
 
RobK
Lost but trying
Profile
Posts: 73
Reg: May 19, 2012
Milton Keynes
6,530
like
12/22/12 06:40 PM (11 years ago)
Just seen this thread. In my spare time I take stats for ice hockey and was asked by the coach if it was possible to assess performance of particular lines. eg how much time is spent in particular zones. My thought at the time was that usng a touchscreen you select the particular line, then when play starts you tap teh screen to start a timer and just drag your finger across the screen in relationship to where the puck is. when the play stops you'd lift your finger to stop the clock. The real time data would then be processed for each line. However it seemed way to comlicated for me but this thread got me thinking about it again, as it seems sort of in the same ballpark (or rink as the case may be!) How difficult would it be to do this?
 
OrchardApps
Code is Art
Profile
Posts: 115
Reg: Jan 11, 2012
Brisbane austra...
5,850
like
05/25/13 04:52 AM (10 years ago)
Thank you sooooo much Kittsy - you rock.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.