Swipe gesture not working when adding as subview ios sdk - ios

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

Related

ECSlidingViewController with UITabBarController

I have a requirement where I need to slide the view but thats inside a UITabBarController.
Does any one tried doing that ? ECSlidingViewController works perfect if I make it rootViewController but I want that in UITabBarController.
I tried setting the ECSlidingViewController as one of the view controllers for the UITabBarController but it keeps crashing after the first swipe or some times it goes in infinite loop
Below is my code
myWorkController = [[TaskWorkViewController alloc] initWithNibName:#"WorkViewController_iPhone" bundle:nil]; // This is the controller where I have my specific logic
myWorkNavController = [[[UINavigationController alloc] initWithRootViewController:myWorkController] autorelease]; // setting the myWorkController to UINavigationController as I need to navigate from this view controller to different view on specific actions
//SlidingviewController setup
self.slidingViewController = [ECSlidingViewController slidingWithTopViewController:myWorkNavController];
self.slidingViewController.topViewController = myWorkNavController;
[myWorkNavController.view addGestureRecognizer:self.slidingViewController.panGesture];
self.slidingViewController.anchorRightPeekAmount = 100.0;
myWorkController.slidingViewController = self.slidingViewController;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[ self.slidingViewController, createNavController, currentWorkNavController];
and I am setting the underRightViewController inside myWorkController
if (self.slidingViewController != nil)
{
UIViewController *underRightViewController = [[[UIViewController alloc] init] autorelease];
// configure under right view controller
underRightViewController.view.layer.borderWidth = 0;
underRightViewController.view.layer.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0].CGColor;
underRightViewController.view.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
underRightViewController.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeBottom | UIRectEdgeRight; // don't go under the top view
self.slidingViewController.underRightViewController = underRightViewController;
}
1) First swipe works perfect but the second swipe breaks in ECSlidingViewController code
2) As I am using UINavigationController, when I try to change underRightViewController it fails at [oldUnderRightViewController removeFromParentViewController]; of ECSlidingViewController code
Can some one please guide me what I am doing wrong or if this is possible with ECSlidingViewController
Thanks in advance

iOS presentViewController View Controller not Fully Loading

With the following code:
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];
//(Yes we are not using ARC yet - kills me)
the view presents but it does not load before fully sliding up to the top. The Nav controller does load properly and you see it slide all the way up. However it's just a frame. In other words, you can see the presenting view controller as the nav controller slides up into place - THEN the mMVC loads.
Thanks for the help!
Your problem is that you are trying to create a UINavigationController while using it as the UINavigationController rootviewcontroller. Fixing this line :
UINavigationController *mMNavVC = [[UINavigationController alloc]
initWithRootViewController:mMNavVC];
to this :
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMVC];
will load the modal view controller before showing it.
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
[[[app window] rootViewController].navigationController pushViewController: mMNavVC animated:YES];
[mMVC release];
[mMNavVC release];
Try adding a line where you access that vc's view, i.e.
MyModalViewController *mMVC = [[MyModalViewController alloc] init];
UINavigationController *mMNavVC = [[UINavigationController alloc] initWithRootViewController:mMNavVC];
mMNavVC.navigationBar.barStyle = UIBarStyleBlackOpaque;
mMVC.view.backgroundColor = [UIColor whiteColor];
[[[appdelegate window] rootViewController] presentViewController:mMNavVC animated:YES completion:nil];
[mMVC release];
[mMNavVC release];
This is kind of a workaround for a problem that your viewController's view doesn't get loaded before navigationController's viewDidAppear method is called. If what I posted doesn't work, the problem is elsewhere.
Just try it and tell if it's ok now. :)
OK. Everybody gets a 1up for their answers because they were all helpful to me.
LucOlivierDB gets the check mark because that was just a stupid thing for me to not have seen.
!!NOTE:!! As it turns out my real problem as this line of code:
self.view.backgroundColor = [UIColor clearColor];
Someone thought it would be clever to have all the views inherit the background by making the view transparent. So when it drew the view it was drawing it transparent. Since the was not considered done drawing until the modal action was done you could see the view beneath it before that.
Thanks guys. You call made me think and learn!

uiswipegesturerecognizer to pass from detail views of an UITableview 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

Facebook Like Notification SubView iOS

I would like to create a subview which loads notifications similar to Facebook in its iOS app. Does anyone know how to build that?
Thanks!
Something like that:
http://www.techarp.com/article/Apple/Facebook_Notifications/facebook.jpg
I suggest you to use a UIPopoverController.
UIViewController *viewController = [[UIViewController alloc] initWithNibName:#"UIViewControllerNibName" bundle:nil];
viewController.delegate = self;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
navController.contentSizeForViewInPopover = CGSizeMake(400, 200);
viewController.contentSizeForViewInPopover = CGSizeMake(400, 200);
poopover.delegate = self;
CGRect rect = CGRectMake(0, 0, yourWidth, yourHeight);
[popover presentPopoverFromRect:locRect inView:parentView permittedArrowDirections:UIPopoverArrowDirectionLeft animated:TRUE];
viewController is the UIViewController inside the popover, and there you can add, for example, a UITableView to show notifications. UIPopoverController is responsible of showing the popup view. Of course in presentPopoverFromRect: method you have to pass the frame the popover anchors to, the view in which present the popover, the arrow directions allowed and the animate flag in order to show the popover in an animated manner. Finally, with delegation you can communicate to the class that is allocing the popover (self.delegate = self).

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