John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 989 forks source link

Getting the Sliding offset as callback #655

Open Zumbalamambo opened 7 years ago

Zumbalamambo commented 7 years ago

I need to animate a uiview when the user slides the sliding menu.To animate the UIView, I need to know the sliding offset when the rear view is sliding. How can I be able to get the offset in real time basis? For instance, I have set that that width of the sliding menu as 300.

Now when the user slides the sliding menu, I would like to get the offset from 0 to 300 when it is sliding.

iDevelopper commented 7 years ago

Use this delegate method:

- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress {
    NSLog(@"Location = %f", location);
}
Zumbalamambo commented 7 years ago

Thanks bro...Should i implement it in MainViewController? Im following Appcoda's example

iDevelopper commented 7 years ago

Yes or in your menu view controller or in AppDelegate

Zumbalamambo commented 7 years ago

@iDevelopper Thanks bro but It is not printing the xLocation coordinates. This is my MainViewController.h file

#import <UIKit/UIKit.h>
#import "SWRevealViewController.h"
@interface MainViewController : UIViewController<SWRevealViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
@end

This is my MainViewController.m file

#import "MainViewController.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = @"Compfie";

    SWRevealViewController *revealViewController = self.revealViewController;
    revealViewController.rearViewRevealWidth = 300;
     revealViewController.delegate = self;
    if ( revealViewController )
    {
        [self.sidebarButton setTarget: self.revealViewController];
        [self.sidebarButton setAction: @selector( revealToggle: )];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }

}

- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress {
    NSLog(@"Location = %f", location);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation

 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

The method revealController is being called but....

  1. The xLocation has to be from 0 to 300 but it is sometimes 0 to 319 or 346 etc...,
  2. It is not printing xLocation while touching the side bar button instead of swiping.

How can I be able to sort this out bro?

iDevelopper commented 7 years ago

No, when tapping the button there is no callback, only willMoveToFrontViewPosition and didMoveToFrontViewPosition. 319 or 346 is the end of your swipe gesture but you know your rearRevealWidth.

Zumbalamambo commented 7 years ago

Thank you bro..May I know the icon size of the slidingmenu icons? It appears big in my app

iDevelopper commented 7 years ago

I use 25 for 1x, 50 for 2x and 75 for 3x.

Zumbalamambo commented 7 years ago

Thanks bro...