0
votes

My xib of BetRecordAniChooserView :

enter image description here

My ViewController in simulator:

You can see the background view of the chooser-view height is reduce.

My code is below:

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

In my 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

You can see in the BetRecordAniChooserView's awakeFromnNib method:

The frame height I set 100:

self.frame = CGRectMake(0, 0, self.bounds.size.width, 100);

But when I start my simulator it become 36(the gray color view under the buttons).

(lldb) po self.frame
(origin = (x = 0, y = 0), size = (width = 375, height = 36))

1

1 Answers

0
votes

I found the reason:

At first I was use the trailing, leading, bottom, top of the gray back view to its superview, I get this issue.

And then I delete the Bottom Space Constraint, and add the height constraint to it.

enter image description here

Then I do not have the issue again, and I can drag out the height Constraint to the .m file too, convenience to change the height.

But I don't know if there is a method I do not use my set height constraint method, still use the trailing, leading, bottom, top constraints to get the requirement effect.