0

私はそれにカスタムビューでナビゲーションバーを持っています。 UIImageViewとUILabelは、titleViewのサブビューです。また、UITapGestureRecognizerをtitleViewに追加して、ユーザーがタップしたときに別のUIViewControllerを表示するようにします。 titleViewをタップすると、他のUIViewControllerが開きます。しかし、UIImageViewの私のtitleViewのサイズが変更されたときに戻るボタンをクリックすると、ここでここでは、コードUIImageViewのサイズが変更されました

UIView *titleView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, 30)]; 
UILabel *title = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width/2, 30)]; 
title.text = _groupName; 
[title setTextColor:[self colorFromHexString:@"#474747"]]; 
[title setFont:[UIFont fontWithName:@"Roboto-Bold" size:16]]; 
[title setTextAlignment:NSTextAlignmentCenter]; 
[title setBackgroundColor:[UIColor clearColor]]; 
_imageView.frame = CGRectMake(0, 0, 30, 30); 
_imageView.layer.cornerRadius = 15.0; 
_imageView.layer.masksToBounds = YES; 
_imageView.layer.borderColor = [UIColor lightGrayColor].CGColor; 
_imageView.layer.borderWidth = 0.1; 
_imageView.contentMode = UIViewContentModeScaleAspectFit; 
title.frame = CGRectMake(title.frame.origin.x+20, title.frame.origin.y, self.view.frame.size.width/2, 30); 
UITapGestureRecognizer *recognizer; 
recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(titleTapped:)]; 
titleView.userInteractionEnabled = YES; 
[titleView addGestureRecognizer:recognizer]; 
[titleView addSubview:title]; 
[titleView setBackgroundColor:[UIColor clearColor]]; 
[titleView addSubview:_imageView]; 
self.navigationItem.titleView = titleView; 

はあなたが私はあなたのコードをチェックし、変更 navigationBar

newViewController

after back

答えて

0

を見ることができるイメージですされる境界にクリップを追加し、する必要はありませんタイトルフレーム2回。

_imageView.frame = CGRectMake(0, 0, 30, 30); 
_imageView.layer.cornerRadius = 15.0; 
_imageView.layer.masksToBounds = YES; 
_imageView.clipsToBounds = true; 
0

ビューのフレームを直接設定するのではなく、Auto Layoutを試してみてください。私は、あなたのカスタムビューが戻るボタンの後に再レイアウトされ、イメージビューのinstrinsicSizeに戻っていることが起こっていると思われます。

代わりに、サブビューでtranslatesAutoresizingMaskIntoConstraintsをオフにしてから配置するための制約を追加し、最終的に画像ビューに幅と高さの制約を追加します。

アプリケーションを国際化する予定がある場合は、自動レイアウトを使用することをお勧めします。制約を正しく設定すると、翻訳されたタイトルが適合し、ハードコードされた値で遊ぶ必要はありません。

関連する問題