Swipe-Right
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(slideToRightWithGestureRecognizer:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
Swipe-Left
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(slideToLeftWithGestureRecognizer:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
On 'slideToRightWithGestureRecognizer' method i want to write code which opens abcViewController which has a viewcontroller on storyboard and same with 'slideToLeftWithGestureRecognizer' to open xyzViewController which also has view controller on storyboard. Without using Navigation View Controller in the program
Should be very easy to accomplish:
When the ViewControllers are connected on your storyboard you could easily do it like this:
- (void)slideToLeftWithGestureRecognizer:(id)sender {
[self performSegueWithIdentifier:#"myConnectionIdentifierHere"]
}
If not:
- (void)slideToLeftWithGestureRecognizer:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myStoryboardName" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"myViewControllerIdentifierHere"];
[self presentViewController:vc animated:YES completion:nil];
}
Have you considered using UIPageViewController? Or does it necessarily have to be a swipe and not a pan gesture (UIPageViewController provides navigation between view controllers using a pan gesture interactively).
Related
I want to implement panel, that by default appears from the bottom only by 1/4.
And when i tap on this part, or swipe it, it should roll out on full screen.
exactly what i want was implemented in this app
So what i tried already:
Making UIView and trying to apply tap and swipe gestures. UIView didn't catch it. But it caught touchesMoved, touchesEnded etc.
UITableView. Same.
Making UIViewController. Ended without any idea how to handle it to right way.
So any ideas or links are appreciated.
Thanks in advance.
Check PPRevealSideViewController https://github.com/ipup/PPRevealSideViewController, I think you can find what you need.
When you tap on the new viewController you can change the Offset.
AppDelegate.m
MainViewController *main = [[MainViewController alloc] init];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
main = [storyboard instantiateViewControllerWithIdentifier:#"MainViewControllerr"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:main];
_revealSideViewController = [[PPRevealSideViewController alloc] initWithRootViewController:nav];
_revealSideViewController.delegate = self;
self.window.rootViewController = _revealSideViewController;
MainViewController.m
-(void)popViewController{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PoppedViewController *pvc = [storyboard instantiateViewControllerWithIdentifier:#"PoppedViewController"];
[self.revealSideViewController pushViewController:pvc onDirection:PPRevealSideDirectionBottom withOffset:_offset animated:_animated completion:nil];
}
PoppedViewController.m
-viewDidLoad{
//...
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(getFullView)];
gesture.delegate = self;
[self.view addGestureRecognizer:gesture];
}
-getFullView{
[self.revealSideViewController changeOffset:0.0f forDirection:PPRevealSideDirectionLeft];
}
In my app I tried to push to a XIB using a long tap event. I did the following code,
In viewDidLoad
UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longPress:)]autorelease];
longPress.delegate = (id<UIGestureRecognizerDelegate>)self;
[self.view addGestureRecognizer:longPress];
[longPress requireGestureRecognizerToFail:doubleTap];
and longPress method is
- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateEnded ) {
ProductDetailViewController *vc = [[[ProductDetailViewController alloc] initWithNibName:#"ProductDetailViewController" bundle:nil] autorelease];
[self.navigationController pushViewController:vc animated:YES];
NSLog(#"Long Press");
}
}
I have a XIB named ProductDetails.xib and I set the File's Owner of it as ProductDetailViewController.
When I'm running this code NSLog is working. But it's not going to the ProductDetails.h. And also There are no errors. How can I fix this? Anyone can help me with this.
Thanks in Advance!
You already have the xib hooked up to the controller, you can achieve that with the following.
ProductDetailViewController *vc = [[[ProductDetailViewController alloc] init] autorelease];
[self.navigationController pushViewController:vc animated:YES];
When I add a UIPopoverController in the ViewDidLoad method, it displays an empty popover view. The same thing happens when I add a UITapGestureRecognizer; it doesn't trigger the attached method. If I put the code in my ViewDidAppear it does work, but in some cases ViewDidAppear is never called, depending on where in my storyboard the view is loaded.
Here's my code:
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] init];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view = popoverView;
pickerPopup = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
pickerPopup.delegate = (id)self;
[pickerPopup setPopoverContentSize:CGSizeMake(320, 240) animated:NO];
And the UITapGestureRecognizer:
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(openPicker:)];
[_form_from addGestureRecognizer:tap];
I solved it for now using a delay in the ViewDidLoad method like so
[self performSelector:#selector(custom_init) withObject:nil afterDelay:0.1];
Still don't get why the UITapGestureRecognizer doesn't trigger. It does work if I attach it to the view, but not if I attach it to a textfield in a static cell.
I need to make my every single UIImageView to be single tapped.
I have a viewController, on this view controller there is a view which i push another views on this view with containment.
I am trying to create gallery ,
What might I be doing wrong?
This is my code;
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Custom initialization
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(openPhotoDetail)];
[self addGestureRecognizer:singleTap];
[self setBackgroundColor:[UIColor lightGrayColor]];
}
return self;
}
-(void)openPhotoDetail
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SideMenu" bundle:[NSBundle mainBundle]];
PhotoDetailViewController *photoDetailViewController = [storyboard instantiateViewControllerWithIdentifier:#"photoDetailViewController"];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.window.rootViewController.menuContainerViewController.centerViewController pushViewController:photoDetailViewController animated:YES];
}
Initially a UIImageView has user interaction disabled. Enalbe the user interaction of your UIImageView and it should work.
imageView.userInteractionEnabled = YES;
In Viewdidload set
YourImageView.userInteractionEnabled = YES;
UITapGestureRecognizer * singleTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(openPhotoDetail:)];
// Instead of self ,give your imageView to add gesture event
[YourImageView addGestureRecognizer: singleTap];
Click on the UIImageView, on storyboard,
Go to Attributes Inspector (The button that looks like a tuxedo, top right ,Second button).
Check the attribute "User Interaction Enabled"
Or if you want to do it by code,
in
-(void)viewDidLoad {
myImageView1.userInteractionEnabled = YES;
myImageView2.userInteractionEnabled = YES;
myImageView3.userInteractionEnabled = YES;
}
UIImageView *MyImageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"XYZ.png"]];
UITapGestureRecognizer *TapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(openPhotoDetail)];
[MyImageview addGestureRecognizer:TapGesture];
[MyImageview setUserInteractionEnabled:YES];
Can u use it like that
I want to put the push Navigation into swipe.
i want to call this method on swipe gesture.
- (IBAction)MakeADifferenceButtonPressed:(id)sender {
MakeADifferenceViewController *makeADifferenceView = [[MakeADifferenceViewController alloc] initWithNibName:#"MakeADifferenceViewController" bundle:nil];
[self.navigationController pushViewController:makeADifferenceView animated:YES];
[makeADifferenceView release];
}
any-one please help me. i am new in iphone.
Use this code to add UISwipeGestureRecognizerDirectionLeft in your current UIView
UISwipeGestureRecognizer *swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(MakeADifferenceButtonPressed:)];
swipeleft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeleft];