プログラムでボタンを作成し、そのフレームをストーリーボードで作成した別のボタンに向けます。向きが変わると、本来の中央にとどまりません。
も作成しますUIImageview
が、向きが変わると真ん中にとどまります
@property (nonatomic, weak) IBOutlet UIImageView *logoImage;
@property (nonatomic, weak) IBOutlet UIButton *loginButton;
@property (strong, nonatomic) UIButton* popUpButton;
UIImage *logOutButtonImage=[UIImage imageNamed:@"Button - Logout.png"];
_popUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_popUpButton setBackgroundImage:logOutButtonImage forState:UIControlStateNormal];
_popUpButton.frame=_loginButton.frame;
[_popUpButton addTarget:self action:@selector(didPressLink:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_popUpButton];
絵コンテの画像とボタン、真ん中にある
画像のプロパティ
ボタンのプロパティ
結果:
didload
向きに関係なく、ビュー上で正常に動作します。
向きが変わっても真ん中に留まらない
ボタンが中央に留まらないのはなぜですか?どうすればそれを達成できますか?