slide the finger from right to left, or vice versa :-) - ios

I am working on application for jokes and I have one feature still missing which is showing jokes text view on the same way of showing photos in Iphone, one by one, and having the user slide the finger from right to left, or vice versa :
Does anyone has an example or knows of one?

You're looking for a UIPageViewController if I'm understanding what you're asking.
Setting up a UIPageViewController is pretty easy.
UIPageViewController *pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
Then simply set the delegate, and create the respective delegate methods, and you're all set!
delegate methods can be referenced from UIPageViewController's class reference.
Good luck! And welcome to Stack Overflow!

Do this for detecting swipes:
UISwipeGestureRecognizer *swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
UISwipeGestureRecognizer *swipeRightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeFrom:)];
swipeLeftRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
// Add it to the view you want
[self.view addGestureRecognizer:swipeLeftRecognizer];
[self.view addGestureRecognizer:swipeRightRecognizer];
//the handler code:
- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
//do something when swiped left.
}
else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
{
//do something when swiped right.
}
}

Related

Page Viewer with Side Menu (Navigation drawer)

I am using REFrostedViewController as a side menu controller, the problem is this menu will appear from any point of screen, I want it to be like the Android version, which will appear only if you start swiping from the start left of screen, if swiping from any other point, the menu will not appear.
I want this because I am having a Page viewer inside this menu.
Since I am new in IOS, I looked inside the library code and didn't find any function that define the starting point also tried to modify the message
panGestureRecognized it didn't work .
So I'd like to suggest me a help or any other library that have the option.
If you have follow this Library then i think you have put this code too
In ViewDidLoad
[self.view addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(panGestureRecognized:)]];
And
- (void)panGestureRecognized:(UIPanGestureRecognizer *)sender
{
// Dismiss keyboard (optional)
//
[self.view endEditing:YES];
[self.frostedViewController.view endEditing:YES];
// Present the view controller
//
[self.frostedViewController panGestureRecognized:sender];
}
Replace Above code with below code.
Confirm UIGestureRecognizerDelegate Delegate protocol
#interface DEMONavigationController () <UIGestureRecognizerDelegate>
In ViewDidLoad
UIScreenEdgePanGestureRecognizer *leftEdgeGesture = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:#selector(handleLeftEdgeGesture:)];
leftEdgeGesture.edges = UIRectEdgeLeft;
leftEdgeGesture.delegate = self;
[self.view addGestureRecognizer:leftEdgeGesture];}
And
- (void)handleLeftEdgeGesture:(UIScreenEdgePanGestureRecognizer *)gesture {
if(UIGestureRecognizerStateBegan == gesture.state ||
UIGestureRecognizerStateChanged == gesture.state) {
[self.frostedViewController presentMenuViewController];
}else{
// DO nothing
}
}

Walking Tour for the first time app user

I am implementing walking tour for the first time user in the application. I do not know is there a better way of doing it, but I have implemented the following approach which detects user taps via tap gesture recognition.
I wonder how could I handle if I have more than one image? Or is there any better or recommended approach for the walking tour?
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIImageView *imageView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"yourimage.png"]];
[self.window addSubview:imageView];
UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
recognizer.delegate = self;
[imageView addGestureRecognizer:recognizer];
imageView.userInteractionEnabled = YES;
self.imageView = imageView;
}
- (void) handleTap:(UITapGestureRecognizer *)recognize
{
[self.imageView removeFromSuperView];
}
Using PageViewController will be another good option for this. You can try this control.
PageViewController
It is totally up to you how you want yo implement this. The approach you have mentioned have nothing wrong.
For your question if you have more than one images then you can create a container view on which you can add multiple imageViews. And On Touch on that container you can show hide image view based on your sequence.

UIScreenEdgePanGestureRecognizer does not react to view controller

I have a view controller that have a label, and I want to perform panning to the right on that label.
So what I did so far is:
*add a pan gesture to the label in the nib file
*created a didPan method:
- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender;
and the implementation:
- (IBAction)didPan:(UIScreenEdgePanGestureRecognizer *)sender {
CGPoint newTranslation = [sender translationInView:self.homeLabel];
self.homeLabel.transform = CGAffineTransformMakeTranslation(newTranslation.x, 0);
}
and changed the screen edge pan gesture recogniser to right.
I thought it should pan now but its now, what am I doing wrong?
tnx
So I had some time to try it out myself.
Here's what the Interface Builder looks like with -didPan IBAction connected.
However that didn't work for me. I did some searching and found this also on StackOverflow.
Possible bug with UIScreenEdgePanGestureRecognizer in Interface Builder
So, I would suggest you try implementing it the old fashion way in code.
Try this:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIScreenEdgePanGestureRecognizer *swipeFromLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:#selector(didPan:)];
swipeFromLeft.edges = UIRectEdgeLeft;
[self.view addGestureRecognizer:swipeFromLeft];
UIScreenEdgePanGestureRecognizer *swipeFromRight = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:#selector(didPan:)];
swipeFromRight.edges = UIRectEdgeRight;
[self.view addGestureRecognizer:swipeFromRight];
}

how to left and right swipe in tableview in iOS sdk

I want to make a tableview in which i want jobs will change to swipe left and right .
By default in iphone swipe is for delete,so how can i make this.
i used gesture for that, but it does not look any transition in tableview,just swipe only,I want swipe transition will show like we are swapping.
Please help !
Method For Left Swipe
UISwipeGestureRecognizer * swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:#selector(swipeleft:)];
swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
[yourtableviewName addGestureRecognizer:swipeleft];
Method For Right Swipe
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self action:#selector(swiperight:)];
[gesture setDirection:UISwipeGestureRecognizerDirectionRight];
[tblvie addGestureRecognizer:gesture];
left Swipe Action Method
-(void)swipeleft:(UISwipeGestureRecognizer*)recognizer
{
int tag = (int)recognizer.view.tag; // assign the tag if u need
if (tag==40)
{
// call the another function
}
else
{
// call the some another function
}
[yourtableview reloadData];
}
Right Swipe Action Method
-(void)swiperight:(UISwipeGestureRecognizer*)recognizer
{
int tag = (int)recognizer.view.tag; // assign the tag if u need
if (tag==40)
{
// call the another function
}
else
{
// call the some another function
}
[yourtableview reloadData];
}

Can't get UISwipeGestureRecognizer to work

I'm making a sidebar on my app so that when you swipe right it opens, I am using this code in the object I made called sidebar:
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.superview action:#selector(swiped)];
[_swipeRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];
[self.superview addGestureRecognizer:_swipeRecognizer];
And this of course crashes and throws the error:
[UIView swiped]: unrecognized selector sent to instance 0x1fdbd0c0
because it's looking for the "swiped" method on self.superview when I want it to look for the method on self, but I want the gesture to be detected on self.superview.
I'm also confused, if I set initWithTarget then why do I have to do addGestureRecognizer? What's the difference between those two things?
Change this:
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self.superview action:#selector(swiped)];
to:
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swiped)];
The call to initWithTarget:action: specifies the class that gets told about the gesture events. The "target" must implement the "action" method.
The call to addGestureRecognizer: specifies which view the gesture must happen on.
In many cases these are the same but in your case they are different.
if you want to handle the gesture recognized in self, at first line, you should set self as the the receiver, not self.superview:
_swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swiped)];
then implement the swiped action:
-(void)swiped:(UIGestureRecognizer *)gestureRecognizer {
//enter code here
}

Resources