Swiping on a Label sholud move one view to another - ipad

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;
}

Related

Making the UINavigationBar Disappear and Appear on a touch, mimicking safari on iOS

I have a UIPageViewController which is called from a UITableViewController and it shows a series of images to the user.
The images contain a lot of information and while it doesn't make sense to have a UINavigationBar the entire time, because it's just used to share the image, or go back, but is there a way to mimic Safari on iOS, where the UINavigationBar at the top disappears and reappears on a touch?
I have not tried anything because I honestly don't have the first clue on where to start with something like this. Is there a third-party open source framework, or an easy way to animate this? Perhaps in the viewDidLoad, have a timer on the UINavigationBar, to show it at the start and disappear after 2 seconds, etc, but then to reappear on a touch?
Any guidance on this would be really appreciated.
iOS 8 provide default feature
self.navigationController.hidesBarsOnTap = true;
[Edited] Add tap gesture in viewDidLoad
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapHandle:)];
[self.view addGestureRecognizer:tapRecognizer];
Add Following method to your viewController
- (void)tapHandle:(UITapGestureRecognizer*)sender {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
if (self.navigationController.navigationBarHidden == NO) {
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
else{
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
});
}
try this code
[[self navigationController] setNavigationBarHidden:YES animated:YES];
[[self navigationController] setNavigationBarHidden:NO animated:YES];

Modal transition - One of the views is seemingly getting deallocated

In my app, I do a search asynchronously. When that completes my mapViewController with pins for the locations is displayed. 2 seconds after that, I do a modal transition over to a listViewController. I set the backgroundcolor like this:
self.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.65];
Making it possible to see the map behind it.
The problem is this: Less then a second after the listView appears you can see the map in the background for a second before it goes away. What I can see in the background now, is the mainViewController the app starts with.
it looks like this:
Less than a second later:
Any help/explanation would be greatly appreciated.
Your view is still transparent, but once your modal controller is at the top of the stack, the view behind it is hidden.
Try using :
yourController.modalPresentationStyle = UIModalPresentationCurrentContext;
[yourController present...];
This code seems to work. I hope it will help.
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
MKMapView *mapView = [MKMapView new];
[self.view addSubview:mapView];
mapView.frame = self.view.bounds;
UIGestureRecognizer *gestureRecognizer = [UITapGestureRecognizer new];
[gestureRecognizer addTarget:self action:#selector(displayTransparentVC)];
[self.view addGestureRecognizer:gestureRecognizer];
}
-(void)displayTransparentVC
{
UIViewController *vc = [TransparentViewController new];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:^{
}];
}

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

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

Resources