我正在尝试根据方向更改更改按钮框架,但按钮操作未检测框架是否更改。
" addButtonsOnScrollView
" 方法是从 " 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);
}