Skip to content

Instantly share code, notes, and snippets.

@osmszk
Last active August 29, 2015 14:04
Show Gist options
  • Save osmszk/ec4c09578d514b18d533 to your computer and use it in GitHub Desktop.
Save osmszk/ec4c09578d514b18d533 to your computer and use it in GitHub Desktop.
addPickerView
BOOL _isShowingPicker;
NSArray *_sizeTexts;
NSInteger _sizeIndex;
@property (strong,nonatomic) UIView *pickerMainView;
@property (strong,nonatomic) UIPickerView *pickerView;
@property (strong,nonatomic) UIBarButtonItem *pickerBarButtonItem;
- (void)initPickerView
{
UIView *pickerMainView = [[UIView alloc] initWithFrame:CGRectMake(0, [PLUtil displaySize].height, 320, 44+216)];
UIWindow *window = ((JOAppDelegate*)([UIApplication sharedApplication].delegate)).window;
[window addSubview:pickerMainView];
self.pickerMainView = pickerMainView;
UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *pickerBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"閉じる" style:UIBarButtonItemStylePlain target:self action:@selector(pushedPickerBarButton:)];
self.pickerBarButtonItem = pickerBarButtonItem;
NSArray *items = @[flexibleSpace,pickerBarButtonItem];
[toolBar setItems:items];
[pickerMainView addSubview:toolBar];
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 320, 216)];
pickerView.delegate = self;
pickerView.dataSource = self;
[pickerMainView addSubview:pickerView];
self.pickerView = pickerView;
_sizeTexts = @[@"小",@"中",@"大"];
}
- (void)togglePicker
{
CGRect frame = _pickerMainView.frame;
[UIView animateWithDuration:0.25f
delay:0.0f
options:UIViewAnimationOptionCurveEaseOut
animations:^{
if (_isShowingPicker) {
_pickerMainView.frame = CGRectMake(0, [PLUtil displaySize].height, frame.size.width, frame.size.height);
}else{
_pickerMainView.frame = CGRectMake(0, [PLUtil displaySize].height-214-44, frame.size.width, frame.size.height);
}
}
completion:^(BOOL finished) {
_isShowingPicker = !_isShowingPicker;
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment