向きの変更に応じてボタンのフレームを変更しようとしていますが、フレームが変更されたかどうかをボタンの操作で検出できません。
" addButtonsOnScrollView
"methodeは" viewWillAppear
"メソッドから呼び出されます
これが私のコードです
//scaleFactor = 320 if portrait orientation scaleFactor= 480 if landscape orientation
- (void) addButtonsOnScrollView
{
containerViewForButtons = [[UIView alloc]initWithFrame:CGRectMake(scaleFactor-100, 22, 100, 37)];
addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton addTarget:self action:@selector(addFriend:)forControlEvents:UIControlEventTouchDown];
[addButton setBackgroundImage:[UIImage imageNamed:@"add_btn.png"] forState:UIControlStateNormal];
addButton.frame = CGRectMake(0, 0, 37, 37);
[containerViewForButtons addSubview:addButton];
[self.view addSubview:containerViewForButtons];
}
- (void) addFriend:(UIButton *) button {
NSLog("Button clicked....");
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self layoutLandscapeView];
}
else if (interfaceOrientation == UIInterfaceOrientationPortrait) {
[self layoutPortraitView];
}
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void) layoutLandscapeView {
containerViewForButtons.frame = CGRectMake(380, 22, 100, 37);
}
- (void) layoutPortraitView {
containerViewForButtons.frame = CGRectMake(220, 22, 100, 37);
}