Right gesture not working - objective-c

In my project, i have two views. One is homeViewController and other is searchViewController. I have done right swipe gesture on homeViewController to show searchViewController. But UISwipeGestureRecognizerDirectionRight doesn't work for me. It gives left animation rather than right.
I have added below code in homeViewController.m to add gesture property and show SearchViewController:
UISwipeGestureRecognizer *swipeRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swipeDetected:)];
[swipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[self.view addGestureRecognizer:swipeRecognizer];
[swipeRecognizer release];
-(void)swipeDetected:(UIGestureRecognizer *)sender
{
SearchViewController *searchView=[[SearchViewController alloc] initWithNibName:#"SearchViewController" bundle:nil];
[self.navigationController pushViewController:searchView animated:YES];
[searchView release];
}
Please help me out.
Thanks.

The animation here is coming as part of the navigation controllers pushViewController:animated: method, it has nothing to do with the direction of the gesture recognizer (that only determines which way the user needs to swipe in order for the swipe to be recogized)
if you want to be able to swipe between view controllers in other directions you could look at UIPageViewController

Related

Flip landscape UIViewController

I have a button in my UIViewController, I want to have Flip transaction when I press the button, I have transaction but it's flip portrait, would you please help me!
I want to have it as Landscape
here is my code :
TestViewController *ctrl = [[TestViewController alloc] init];
[UIView transitionFromView:self.view
toView:ctrl.view
duration:1
options:UIViewAnimationOptionTransitionFlipFromTop
completion:nil];
[self.navigationController pushViewController:ctrl animated:NO];
Thanks in advance!
What you're doing is illegal in any case. You may not transition your own view (self.view) out of the view hierarchy. Either transition a subview of self.view to a different subview of self.view, or else, if you want to use views belonging to view controllers, set up a system of parents and children and manage them properly (and, in general, call transitionFromViewController:toViewController:duration:options:animations:completion:).
If what you're trying to do is summon the view of a different view controller, then use one of the methods that does that, such as presentViewController:animated:completion:.

Transparent UIView on top detecting touches

I have an iPad project structured with a UISplitViewController:
RootViewController
DetailviewController
Both of them are detecting touches with Gesture Recognizer inside their own Class.
I would like to create a transparent UIView on top of all the Classes to detect ONLY a Diagonal Swipe (from the left bottom corner to the right top corner).
So, when the swipe will be detected I will launch a function otherwise nothing appended and the touch should be passed on the low level view.
I tried these two solutions:
Add a GestureRecognizer on this top transparent view but this will hide all touches to the lower hierarchy views.( with userInteraction enabled: YES ofcourse);
The other solution is to make the init like this
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setBackgroundColor:[UIColor colorWithWhite:1 alpha:0.01]];
[self setUserInteractionEnabled:NO];
}
return self;
}
and try to detect the swipe with
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
But at this point all the touches are not detected.
Anybody have a nice solution?
I will not create a transparent UIView like you are mentioning. I will add a UISwipeGestureRecognizer to the UISplitViewController's view this is already the view that contains all your subviews. You can have access to the view within the app delegate:
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
// attach the swipe gesture to the view that embeds the rootView and the detailView
UISwipeGestureRecognizer* swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:splitViewController.view action:#selector(swipeUpdated:)];
Can't you just add a gesture recognizer to the UISplitViewController's view?
You should look into Container Controllers. You can make your own SplitViewController and make a third view on top of the controller that detects the swipe. Custom container controllers are pretty straight forward and gives you a lot of flexibility.

Adding UITapGestureRecognizer to UINavigationBar overrides ability to use ScrollToTop

So Ive added a TapGestureRecognizer to the navigation bar in order to "pull down" another view, thus its a UIPanGesture Recognizer. The problem is when this gesture is added the UITableView scrollToTop method no longer works, even if enabled before or after the addition of the gesture recognizer.
Has anyone ever experienced or can think of an easy solution?
Thanks!
Heres My Code:
if (!pan) {
_pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panaction:)];
[_pan setMaximumNumberOfTouches:1];
}
_pan.delegate = self;
[self.navigationController.navigationBar addGestureRecognizer:_pan];
EDIT:
Ok, the problem seems to be adding a UIView as a subview in order to drag down from the UINavigation bar, when I dont add the subview the scrollToTop works fine, once its added it must be intercepting the touch event underneath the status bar..

EXC_BAD_ACCESS at removeFromSuperview - using ARC

In one of my ViewControllers (ViewController A), I have the following code:
AlertViewController *aViewController = [[AlertViewController alloc] initWithNibName:#"AlertViewController" bundle:nil];
[self.view addSubview:[aViewController view]];
[self.view bringSubviewToFront:[aViewController view]];
And in AlertViewController, I have a button and when the user clicks on it, I have:
[self.view removeFromSuperview];
Whenever I click the button, the result is EXC_BAD_ACCESS.
I'm unable to figure out the problem. My project is using ARC and ViewController A is part of a navigation controller stack if that info helps.
The problem here is that the UIView doesn't own its UIViewController. In the first block of code you held the UIView around by adding it to a subview, but let the UIViewController go away. The UIView from a UIViewController is special, you can't let this happen.
Make sure the UIViewController that created the UIView lives as long as the view does.

Superview is Nil after Second Launch of View Controller

I've spent hours and I cant figure this out. I have a detail view controller (UITableView) which is launched here:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EventLocationDetailController *newDetailViewController = [[EventLocationDetailController alloc] initWithNibName:#"EventLocationDetailController" bundle:nil];
self.eventDetailController = newDetailViewController;
[self.navigationController pushViewController:self.eventDetailController animated:YES];
[newDetailViewController release];
}
In the detail view controller there is a button method which calls the below method to display a slide-in-slide-out animation confirming the users choice:
-(void)confirmLastActionWithMessage:(NSString *)message {
ConfirmActionViewController *newConfirmActionViewController = [[ConfirmActionViewController alloc] initWithNibName:#"ConfirmActionViewController" bundle:nil];
self.confirmActionViewController = newConfirmActionViewController;
[newConfirmActionViewController release];
[[self.view superview] addSubview:self.confirmActionViewController.view];
}
Protocol method called by the ConfirmActionViewController indicating that the animation is finished.
-(void)didFinishConfirmDisplay:(UIView *)viewToRemoveFromSuperview {
[viewToRemoveFromSuperview removeFromSuperview];
}
This works perfect the first time I press the button. If I pop the detail controller and push it back on to the stack and press the button again, nothing happens and the detail controller's superview is nil every time I invoke the method after that. Superview is not nil in the viewWillAppear method for the detail view, only when It gets to the confirmLastActionWithMessage method. No other user interaction happens in between. How do I get the superview back? I have a similar code that works without animation.
I've also noticed that the detail view controller hasn't called dealloc when popped off the stack. Not sure where the problem is.
Thanks.
EDIT 1
OK. I replaced the addSubview line with this one:
[self.view insertSubview:self.confirmActionViewController.view atIndex:0];
and the animation view appeared underneath one of the table cells. Could one of the table cells steal the superview?
Well I don't really understand why you should add the subview to the superview. Why not add it just to self.view
I may not be able to explain why there is no superview but try either adding the controller view to self.view or
[[[[UIApplication sharedApplication] delegate] window] addSubview:yourview];
This will render the view on top of everything.