Skip to content

Commit

Permalink
iPhone X preview
Browse files Browse the repository at this point in the history
  • Loading branch information
zonghongyan committed Oct 20, 2017
1 parent 76847aa commit 42b781b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
35 changes: 14 additions & 21 deletions EVNCustomSearchBar/EVNCustomSearchBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ - (CGSize)intrinsicContentSize
- (void)initView
{
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 44);

[self addSubview:self.cancelButton];
if (!_isHiddenCancelButton)
{
[self addSubview:self.cancelButton];
self.cancelButton.hidden = YES;
}

[self addSubview:self.textField];
self.cancelButton.hidden = YES;

// self.backgroundColor = [UIColor colorWithRed:0.733 green:0.732 blue:0.756 alpha:1.000];

[self addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
Expand Down Expand Up @@ -122,21 +125,15 @@ - (void)setIconAlign:(EVNCustomSearchBarIconAlign)iconAlign

- (void)ajustIconWith:(EVNCustomSearchBarIconAlign)iconAlign
{
if (_iconAlign == EVNCustomSearchBarIconAlignCenter && ([self.text isKindOfClass:[NSNull class]] || !self.text || [self.text isEqualToString:@""] || self.text.length == 0))
if (_iconAlign == EVNCustomSearchBarIconAlignCenter && ([self.text isKindOfClass:[NSNull class]] || !self.text || [self.text isEqualToString:@""] || self.text.length == 0) && ![_textField isFirstResponder])
{
_iconCenterImgV.hidden = NO;
_textField.frame = CGRectMake(7, 7, self.frame.size.width - 7*2, 30);
_textField.textAlignment = NSTextAlignmentCenter;

CGSize titleSize; // 输入的内容或者placeholder数据
// if ([self.text isKindOfClass:[NSNull class]] || !self.text || [self.text isEqualToString:@""] || self.text.length == 0)
// {
// titleSize = [self.text sizeWithAttributes: @{NSFontAttributeName:_textField.font}];
// }
// else
// {

titleSize = [self.placeholder?:@"" sizeWithAttributes: @{NSFontAttributeName:_textField.font}];
// }

NSLog(@"----%f", _textField.frame.size.width);
CGFloat x = _textField.frame.size.width/2.f - titleSize.width/2.f - 30;
Expand Down Expand Up @@ -230,15 +227,11 @@ - (void)setInputView:(UIView *)inputView
_inputView = inputView;
_textField.inputView = _inputView;
}
//- (BOOL)isUserInteractionEnabled
//{
// return YES;
//}
//
//- (BOOL)canBecomeFirstResponder
//{
// return YES;
//}

- (BOOL)isUserInteractionEnabled
{
return YES;
}

- (void)setInputAccessoryView:(UIView *)inputAccessoryView
{
Expand Down Expand Up @@ -401,7 +394,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
{
if ([object isEqual:self] && [keyPath isEqualToString:@"frame"])
{
// _textField.frame = CGRectMake(7, 7, self.frame.size.width - 7*2, 30);
// _textField.frame = CGRectMake(7, 7, self.frame.size.width - 7*2, 30);
NSLog(@"----%f", self.frame.size.width);
[self ajustIconWith:_iconAlign];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ @interface LeftRightViewController ()

@implementation LeftRightViewController

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

// 弹出键盘
// [self.searchBar becomeFirstResponder];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

// 弹出键盘
[self.searchBar becomeFirstResponder];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ @interface LeftViewController ()

@implementation LeftViewController

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

// 弹出键盘
[self.searchBar becomeFirstResponder];
}

- (void)viewDidLoad
{
[super viewDidLoad];
Expand Down

0 comments on commit 42b781b

Please sign in to comment.