0
我BetRecordAniChooserView的廈門國際銀行:當我動畫自定義視圖,視圖的高度改變
我的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
你可以見所述BetRecordAniChooserView
的awakeFromnNib
方法:
框架高度I設定100
:
self.frame = CGRectMake(0, 0, self.bounds.size.width, 100);
但是,當我開始模擬器它成爲36
(下的按鈕的灰色圖)。
(LLDB)PO self.frame
(原點=(X = 0,Y = 0),大小=(寬度= 375,高度= 36))