uiswipegesturerecognizer to pass from detail views of an UITableview IOS - ios

I have an UITableView to display some elements, when I click in each cell I can see its detailViewController. I would like to pass from one detailViewController to the next making an UISwipeGestureRecognizer to left, and if I make UISwipeGestureRecognizer to right, get back to the tableView.
Thank you

Add the swipe recognizer to your view or tableview
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(goToNextView)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft]; //Add to the view or tableview or whatever
Add the method
- (void)goToNextView
{
YourViewController *vc =
[self.storyboard instantiateViewControllerWithIdentifier:#"yourViewControllerIdendifier"];
[self.navigationController pushViewController:vc animated:YES];
}
Do the same to go back but instead of using push, use pop

Related

how make view transition like iPad appstore on iOS 7

I want to make a view transition, like iPad AppStore on iOS 7, click a item(app) and popping a detail view with flip vertical, and tapping outside of detail view will dismiss, this view transition is neither like popover and modal transition.
So, how can I make this transition...
Appreciation for your help.
Also looking for the transition animation. But I did figure out how to accomplish the tapping outside of window to dismiss/close. It can be found here.
In your viewDidAppear you create a UITapGestureRecognizer and add it to the view's window. Like so:
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapBehind:)];
[recognizer setNumberOfTapsRequired:1];
recognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:recognizer];
handleTapBehind checks to see is the Gesture's state has ended and get's the location of the tap and dismisses the view/window
- (void)handleTapBehind:(UITapGestureRecognizer *)sender{
if (sender.state == UIGestureRecognizerStateEnded){
CGPoint location = [sender locationInView:nil]; //Passing nil gives us coordinates in the window
//Check to see if it's in or outside. If outside, dismiss the view.
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]){
// Remove the recognizer first so it's view.window is valid.
[self.view.window removeGestureRecognizer:sender];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
Hope this helps!
Start here. This is an example:
[UIView transitionWithView:newView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{ // put the animation block here
}
completion:NULL];

iOS app crashes at tap gesture event

I have a view targeted for iPad that I present modally with modalPresentationStyle property set to UIModalPresentationFormSheet, by pushing firstly its view controller into a navigation controller:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myViewController];
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
Then, in the presented view controller, I want to detect tap gestures outside itself (as I said, I present it as a form sheet), so I have set a tap gesture this way:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleTap:)];
self.tapGestureRecognizer.numberOfTouchesRequired = 1;
self.tapGestureRecognizer.numberOfTapsRequired = 1;
self.tapGestureRecognizer.cancelsTouchesInView = NO;
[self.view.window addGestureRecognizer:self.tapGestureRecognizer];
}
- (void)handleTap:(UITapGestureRecognizer*)sender
{
if (sender.state == UIGestureRecognizerStateEnded) {
CGPoint location = [sender locationInView:nil];
if (![self.view pointInside:[self.view convertPoint:location fromView:self.view.window] withEvent:nil]) {
[self.view.window removeGestureRecognizer:sender];
[self dismissModalViewControllerAnimated:YES];
}
}
}
The navigation controller I'm presenting modally, and whose root view controller is the one setting this gesture recognizer, displays more views in hierarchy. When only the root view controller is pushed onto the navigation controller stack and I use the tap gesture outside it, it is correctly dismissed and I'm able to present modally this root view controller again. When I navigate from the root view controller and I push one more view controller onto the navigation stack, the tap gesture still works, but then the app crashes when I try to show the form sheet again.
How should I handle this gesture and the behavior I want having a navigation hierarchy?
Thanks in advance
I think your problem is removing the gesture recognizer with self.view.window -- that will be nil when another controller is pushed on the stack, since only the view on screen has a non-nil window property. Try replacing that with [UIApplication sharedApplication].delegate.window and see if that fixes the problem.
One of the possible cause of crash I've encountered is forgetting to declare your view controller as a childViewController to its parent controller.

dismiss presentModalViewController not working over UIScrollView

In my app I am using presentModalViewController and in the next controller I have used UIScrollView, also to dismiss presentModalViewController UITapGestureRecognizer is used
My code is like,
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tappedOnView:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
tapGesture.delegate = self;
[self.fullScreenImageView addGestureRecognizer:tapGesture];
-(void)tappedOnView:(UIGestureRecognizer*)gestureRecognizer {
[self dismissModalViewControllerAnimated:YES];}
But it gives me an error
attempt to dismiss modal view controller whose view does not currently appear. self = <UITabBarController: 0xabb0610> modalViewController = <FullScreenViewController: 0xab5c440>
So I replace the calling way like
if ([self respondsToSelector:#selector(presentingViewController)]) {
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}
But the code doesn't work. I can't dismiss my presentModalViewController.
Without scroll view its working. What is wrong in above code?
tapGesture.delegate = self;
is not needed over there.
[self.fullScreenImageView addGestureRecognizer:tapGesture];
if fullScreenImageView is a scrollView then tapGesture already implemented over there. That might be the problem.

Swipe gesture not working when adding as subview ios sdk

I spent entire weekend trying to figure out why my gestures are not working. When I present as a model view gestures are working but when I add as a subview gestures are not working. Is there any reason why its not working only when added as subview.
This code Works:
myVC = [[FullViewController alloc] initWithNibName:#"FullViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: myVC];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigationController animated:YES];
navigationController.view.superview.bounds = CGRectMake(0,0,1024,724);
This code does not work:
myVC = [[FullViewController alloc] initWithNibName:#"FullViewController" bundle:nil];
myVC.view.frame = CGRectMake(0, 0, 1024, 724);
myNavCtrl = [[UINavigationController alloc] initWithRootViewController:myVC];
[self.view addSubview: myNavCtrl.view];
myNavCtrl.view.frame = CGRectMake(0, -20, 1024, 675);
Gesturerecognizer code:
swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self.view addGestureRecognizer:swipeLeft];
Any help would be apprenticed.
Looks to me like the superview is not allowing touches or user interaction. Can't say exactly why with the code snippet you provide, but you can try adding a gesture recognizer to the superview and see if that works, if it doesn't then the problem is with the superview.
It works as modal because it does not use the other view at all.
Without seeing handleSwipeLeft details:
It looks like you are setting a UIGestureRecognizer and telling it call the selector/ method : handleSwipeLeft.
You should declare your UIGestureRecognizer in your View Controller but set the target as your UIView subclass and then implement handleSwipeLeft in your UIView subclass.
Hope that works

Swiping on a Label sholud move one view to another

I have a requirement in which I need to swipe on a label and after swiping on it,it should take me to the other view.
Will it be possible. The Label should be self explanatory as it should change the color and should get a blinking effect so that the user knows to swipe there.
Please suggest me.
Thanks
Rizwan
The best thing to do is to create a gesture and attach that gesture to the uilabel, heres a simple example
UISwipeGestureRecognizer *swipe;
swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(Gest_SwipedLeft:)];
[swipe setDirection:UISwipeGestureRecognizerDirectionLeft];
[label addGestureRecognizer:swipe];
[swipe release];
Then simply apply your code to push the next nib
-(void)Gest_SwipedLeft:(UISwipeGestureRecognizer *) sender
UI_iPad_View *controller = [[UI_iPad_View alloc] initWithNibName:#"ipadview" bundle:nil];
[[self navigationController] pushViewController:controller animated:YES];
// Cleanup
[controller release], controller = nil;
}

Resources