縦向きと横向きの両方で UITabBar のすぐ上に配置したい UIView があります。これをプログラムで実行したいと思います。
これが私のUIViewサブクラスにあるすべてですIPChatTextView
:
/* Initialization */
- (id)init
{
if (self = [super init])
{
// Set frame
self.frame = CGRectMake(0, 0, 320, 40);
// Create background
UIEdgeInsets insetsBackground = UIEdgeInsetsMake(20, 50, 19, 82);
UIImage *imageBackground = [[UIImage imageNamed:@"ChatTextView_Background.png"] resizableImageWithCapInsets:insetsBackground];
UIImageView *imageViewBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
imageViewBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth;
imageViewBackground.image = imageBackground;
// Add subviews
[self addSubview:imageViewBackground];
}
return self;
}
画像ビューimageViewBackground
は UIView 全体を埋める必要があるため、自動サイズ変更マスクを に設定しましたUIViewAutoresizingFlexibleWidth
。これはうまくいきます。
ビューを初期化するときに、自動サイズ変更マスクを設定しました。
self.chatTextView = [[IPChatTextView alloc] init];
self.chatTextView.frame = CGRectMake(0, 327, 320, 40);
self.chatTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:self.chatTextView];
Interface Builder に UIView を追加して、下の画像のように自動サイズ変更マスクを設定してみましたが、完全に機能します。
上の画像と同じ自動サイズ変更を行いたい場合は、以下のコードのようにプログラムで行うと思いましたが、同じ結果にはなりません。self.chatTextView
代わりに、上から約 2/3 に配置されています。これは、タブ バーのすぐ上にある 327 にの y 位置を設定すると奇妙に見えます。
self.chatTextView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
ビューを縦向きと横向きの両方でタブバーの上に配置したいときに、自動サイズ変更マスクを設定する方法を知っている人はいますか?
編集:
自動サイズ変更マスクをUIViewAutoresizingMaskFlexibleBottomMargin
の代わりに含めるように変更するUIViewAutoresizingMaskFlexibleTopMargin
と、縦向きモードではビューがタブ バーの上に配置されますが、横向きモードでは画面からはみ出してしまいます。