Giter VIP home page Giter VIP logo

ayslidingpickerview's Introduction

AYSlidingPickerView

Version License Platform

Implementation of a picker view that can be shown by either tapping on or panning the navigation bar.

AYGestureHelpView

Usage

AYSlidingPickerView can be used either as a singleton or as a regular object. In both cases it is necessary to specify the mainView and items properties.

mainView is simply the view that is currently displayed in the app's window. In most cases, it's just self.view in a view controller.

items must consist of AYSlidingPickerViewItem objects. You can generate them as follows:

NSMutableArray *items = [NSMutableArray new];
for (NSString *title in titles) {
  AYSlidingPickerViewItem *item = [[AYSlidingPickerViewItem alloc] initWithTitle:title handler:^(BOOL completed) {
    // Action to be performed on selection
  }];
  [items addObject:item];
}

For more information, please refer to the example and documentation.

Installation

AYSlidingPickerView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "AYSlidingPickerView"

Author

Ayan Yenbekbay, [email protected]

License

Copyright (c) 2015 Ayan Yenbekbay <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

ayslidingpickerview's People

Contributors

yenbekbay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ayslidingpickerview's Issues

AYSlidingPickerView is not moved to back

Hi,
My use case is quite simple:
I have 2 view controllers let say A, B (A is in a navigation controller). Flow is:

  • From A I tap a button to display B to create a new data record.
  • From B I tap another button to dismiss B and add that record to A's property (NSMutableArray*).
  • In A's viewWillAppear I check if number of records > 0 then I add them to AYSlidingPickerView

The problem is:

  • If I display B using [A.navigationController pushViewController:animated:] then AYSlidingPickerView works normally.
  • If I display B using [A presentViewController:animated:completion:] then when B is dismissed the AYSlidingPickerView will be displayed above A so I can not do anything with A anymore.

My fix:
For now to fix it I put AYSlidingPickerView to back again in [A viewDidAppear:] as shown in code below but I feel like a hack so I hope you can take a look and suggest a better fix.

Code of A:

#import "ViewController.h"
#import "ItemViewController.h"
#import <AYSlidingPickerView/AYSlidingPickerView.h>

@interface ViewController () {
    NSMutableArray *texts;
    AYSlidingPickerView *pickerView;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    texts = [[NSMutableArray alloc] init];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if ([texts count] > 0) {
        pickerView = [AYSlidingPickerView sharedInstance];

        NSMutableArray *items = [[NSMutableArray alloc] initWithCapacity:[texts count]];
        for (NSString *s in texts) {
            AYSlidingPickerViewItem *item = [[AYSlidingPickerViewItem alloc] initWithTitle:s handler:^(BOOL completed) {
                self.navigationController.title = s;
            }];
            [items addObject:item];
        }
        pickerView.mainView = self.view;
        pickerView.items = items;
        pickerView.selectedIndex = 0;
        pickerView.closeOnSelection = YES;
        [pickerView addGestureRecognizersToNavigationBar:self.navigationController.navigationBar];
    }

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    // To ensure picker view is sent to back
   [[UIApplication sharedApplication].delegate.window sendSubviewToBack:pickerView];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [pickerView removeGestureRecognizersFromNavigationBar:self.navigationController.navigationBar];
}

- (IBAction)addItem:(id)sender {
    ItemViewController *ivc = [self.storyboard instantiateViewControllerWithIdentifier:@"ItemViewController"];
    ivc.texts = texts;
    [self presentViewController:ivc animated:YES completion:nil];
//    [self.navigationController pushViewController:ivc animated:YES];

}

Code of B:

#import "ItemViewController.h"

@interface ItemViewController ()
@property (weak, nonatomic) IBOutlet UITextField *textToAdd;

@end

@implementation ItemViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  [formatter setDateStyle:NSDateFormatterFullStyle];

  self.textToAdd.text = [formatter stringFromDate:[NSDate date]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)addItemTapped:(id)sender {
  [self.texts addObject:self.textToAdd.text];
  [self dismissViewControllerAnimated:YES completion:nil];
//    [self.navigationController popViewControllerAnimated:YES];
}

@end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.