2017-05-16 109 views
0

我BetRecordAniChooserView的廈門國際銀行:當我動畫自定義視圖,視圖的高度改變

enter image description here

我的ViewController在模擬器:

你可以看到背景圖選擇器視圖高度的降低。

我的代碼如下:

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 

你可以見所述BetRecordAniChooserViewawakeFromnNib方法:

框架高度I設定100

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

但是,當我開始模擬器它成爲36(下的按鈕的灰色圖)。

(LLDB)PO self.frame
(原點=(X = 0,Y = 0),大小=(寬度= 375,高度= 36))

回答

0

我發現的原因:

起初我使用灰色後視圖的尾部,頂部,底部,頂部到它的超級視圖,我得到這個問題。

然後我刪除底部空間約束,並將高度約束添加到它。

enter image description here

然後,我不要再有問題,我可以拖出高度約束到.m文件也方便更換的高度。

但我不知道是否有一種方法,我不使用我的設置高度約束方法,仍然使用尾隨,領先,底部,頂部約束來獲得需求的影響。

相關問題