正在嘗試根據方向更改更改按鈕幀,但按鈕操作未檢測到幀是否更改。更改按鈕幀時按鈕操作不起作用
「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);
}
感謝它爲我工作...非常感謝。 –