yzc577亚洲城亚洲娱乐第一站添加到toolBar中的barButtonItem无法响应

( yzc577亚洲城亚洲娱乐第一站 )

#import "CategoryPickerView.h"
#import "Masonry.h"

@interface CategoryPickerView 

@property nonatomic, strong UIToolbar *pickerTool;

@end

@implementation CategoryPickerView

@synthesize delegate;

- instancetypeinitWithFrame:CGRectframe {
    self = [super initWithFrame:frame];
    if self {
        [self configureToolBarAndPickerView];
    }
    
    return self;
}

- voidconfigureToolBarAndPickerView {
    _pickerTool = [[UIToolbar alloc] initWithFrame:CGRectZero];
    _pickerTool.backgroundColor = [UIColor lightGrayColor];
    
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selectorcancel];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selectordone];
    UIBarButtonItem *alertButton = [[UIBarButtonItem alloc] initWithTitle:@"abc" style:UIBarButtonItemStylePlain target:self action:@selectoralert];
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [_pickerTool setItems:[NSArray arrayWithObjects:cancelButton, flexibleSpace, alertButton, flexibleSpace, doneButton, nil]];
    
    [self addSubview:_pickerTool];
    
    _picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
    [self addSubview:_picker];
    
    [self configureLayoutInView];
}

- voidconfigureLayoutInView {
    [_pickerTool mas_makeConstraints:^MASConstraintMaker *make {
        make.top.mas_equalTo0;
        make.leading.mas_equalTo0;
        make.trailing.mas_equalTo0;
        make.height.mas_equalTo32;
    }];
    
    [_picker mas_makeConstraints:^MASConstraintMaker *make {
        make.top.equalTo_pickerTool.mas_bottom;
        make.leading.equalTo_pickerTool.mas_leading;
        make.trailing.equalTo_pickerTool.mas_trailing;
//        make.bottom.equalToself.mas_bottom;
    }];
}

- voidcancel {
    if delegate {
        [delegate cancelButtonPressed];
    }
}

- voiddone {
    if delegate {
        [delegate doneButtonPressed];
    }
}

- voidalert {
    
}

- voidshowInView:UIView *view {
    [view addSubview:self];
    [self mas_makeConstraints:^MASConstraintMaker *make {
        make.leading.equalToview.mas_leading;
        make.trailing.equalToview.mas_trailing;
        make.top.equalToview.mas_bottom.with.offset0;
    }];
    
    [self layoutIfNeeded];
    
    [UIView animateWithDuration:0.4
                     animations:^{
                         [self mas_updateConstraints:^MASConstraintMaker *make {
                             make.top.equalToview.mas_bottom.with.offset-248;
                         }];
                         [self layoutIfNeeded];
                     }
                     completion:^BOOL finished {
                         
                     }
     ];
}

- voidhideFromView:UIView *view {
    [self layoutIfNeeded];
    [UIView animateWithDuration:0.4
                     animations:^{
                         [self mas_updateConstraints:^MASConstraintMaker *make {
                             make.top.equalToview.mas_bottom.with.offset0;
                         }];
                         [self layoutIfNeeded];
                     }
                     completion:^BOOL finished {
                         [self removeFromSuperview];
                     }
     ];
}

@end

我在viewcontroller中的viewwillappear方法中init了一个CategoryPickerView,
这三个button都无法响应

(看完/读完)这篇文章有何感想! yzc577亚洲城亚洲娱乐第一站的分享…

发表评论

电子邮件地址不会被公开。 必填项已用*标注