我的BetRecordAniChooserView的xib:
模拟器中的我的ViewController:
您可以看到选择器视图高度的背景视图是reduce。
我的代码如下:
BetRecordAniChooserView.h:
#import <UIKit/UIKit.h>
typedef void(^ChooseBlock)(NSString *choosedStr);
@interface BetTRecordAniChooserView : UIView
@property (nonatomic, assign) UIViewController *owener;
@property (nonatomic, assign) BOOL isShow;
@property (nonatomic, copy) ChooseBlock block;
- (void)showSelf;
- (void)hideSelf;
@end
BetRecordAniChooserView.m:
#import "BetTRecordAniChooserView.h"
@interface BetTRecordAniChooserView ()
@property (weak, nonatomic) IBOutlet UIButton *all_button;
@property (weak, nonatomic) IBOutlet UIButton *check_pending_button;
@property (weak, nonatomic) IBOutlet UIButton *deposited_button;
@property (weak, nonatomic) IBOutlet UIButton *have_cancel_button;
@end
@implementation BetTRecordAniChooserView
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
- (void)awakeFromNib {
[super awakeFromNib];
self.frame = CGRectMake(0, 0, self.bounds.size.width, 100);
self.all_button.selected = YES;
}
#pragma mark - actions
- (IBAction)allAction:(UIButton *)sender {
self.block(sender.titleLabel.text);
}
- (IBAction)checkPendingAction:(UIButton *)sender {
self.block(sender.titleLabel.text);
}
- (IBAction)haveDepositeAction:(UIButton *)sender {
self.block(sender.titleLabel.text);
}
- (IBAction)haveCancelAction:(UIButton *)sender {
self.block(sender.titleLabel.text);
}
#pragma mark - methods
- (void)showSelf {
CGRect temp_frame = self.frame;
self.isShow = YES;
[UIView animateWithDuration:0.3 animations:^{
self.frame = CGRectMake(temp_frame.origin.x, temp_frame.origin.y + temp_frame.size.height, temp_frame.size.width, temp_frame.size.height);
}];
}
- (void)hideSelf {
CGRect temp_frame = self.frame;
self.isShow = NO;
[UIView animateWithDuration:0.3 animations:^{
self.frame = CGRectMake(temp_frame.origin.x, temp_frame.origin.y - temp_frame.size.height, temp_frame.size.width, temp_frame.size.height);
} completion:^(BOOL finished) {
}];
}
@end
在我的ViewController.m中:
#import "ViewController.h"
#import "BetTRecordAniChooserView.h"
@interface ViewController ()
{
BetTRecordAniChooserView *_chooser_view;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_chooser_view = [[NSBundle mainBundle] loadNibNamed:@"BetTRecordAniChooserView" owner:self options:nil].firstObject;
//float width = self.view.bounds.size.width;
//float height = 100.f;
//_chooser_view.frame = CGRectMake(0, -height + 64, width, height);
_chooser_view.owener = self;
[self.view addSubview:_chooser_view];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)actionA:(UIButton *)sender {
if (_chooser_view.isShow) {
[_chooser_view hideSelf];
} else {
[_chooser_view showSelf];
}
}
@end
您可以在BetRecordAniChooserView
awakeFromnNib
方法中看到:
我设置的框架高度100
:
self.frame = CGRectMake(0, 0, self.bounds.size.width, 100);
但是当我启动我的模拟器时,它变为36
(按钮下方的灰色视图)。
(lldb)po self.frame
(origin =(x = 0,y = 0),size =(width = 375,height = 36))