こんにちは私のアプリでは、下の図のようなビューにいくつかのuiButtonsがサブビューとして追加されています。 alt text http://img193.imageshack.us/img193/5931/landscapeq.png自動回転時にフレームが設定された後にUIButtonsが反応しない
当初ビューはボタンがタッチに対応ポートレートモードのとき:ユーザーは風景の中に携帯電話を回転させたときのビューとボタンがこれにポジションを変更する必要があります alt text http://img99.imageshack.us/img99/5244/portraitc.png
。私が電話機を傾けると、ボタンが動いて、2番目の画像のようにすべてが表示され、ボタンがタッチに反応します。電話機をポートレートモードに戻すと、ボタンは元の状態に戻りますが、タッチには反応しません。私は戻って風景に変更した場合のボタンが正しく動作し...
私のボタンは、次のように作成されます。
nextNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25)];
[nextNewsP setImage:[UIImage newImageFromResource:@"next_arrow.png"] forState:UIControlStateNormal];
[nextNewsP addTarget:self action:@selector(nextNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[nextNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:nextNewsP];
[nextNewsP release];
previousNewsP = [[UIButton alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25)];
[previousNewsP setImage:[UIImage newImageFromResource:@"previous_arrow.png"] forState:UIControlStateNormal];
[previousNewsP addTarget:self action:@selector(previousNewsAction:) forControlEvents:UIControlEventTouchUpInside];
[previousNewsP setShowsTouchWhenHighlighted:TRUE];
[bottomTools addSubview:previousNewsP];
[previousNewsP release];
bottomToolsは図であり、このようなサブビューとしても追加されます。
[self.view addSubview:bottomTools];
[bottomTools release];
と私のshouldAutorotateToInterfaceOrientation機能は次のようになります。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[UIView beginAnimations:@"moveViews" context: nil];
if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@"set frames for portrait");
closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 30, 2, 23, 25);
newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.width - 10, 22);
internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 55, 5, 18, 18);
industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height-40, [[UIScreen mainScreen] bounds].size.width, 40);
nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 40, 10, 25, 25);
previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.width - 85, 10, 25, 25);
}
else
{
NSLog(@"set frames for landscape");
closeView.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 30, 2, 23, 25);
newsInfo.frame = CGRectMake(10, 10, [[UIScreen mainScreen] bounds].size.height - 10, 22);
internetActivityIndicator.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 55, 5, 18, 18);
industryLabel.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height/2.0 - [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width/2, 3, [industryTitle sizeWithFont:[UIFont systemFontOfSize:14]].width, 22);
bottomTools.frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.width-40, [[UIScreen mainScreen] bounds].size.height, 40);
nextNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 40, 10, 25, 25);
previousNewsP.frame = CGRectMake([[UIScreen mainScreen] bounds].size.height - 85, 10, 25, 25);
}
[UIView commitAnimations];
return YES;
}
これまでに同様の問題がありましたか? ありがとうございます、 ソリン
ありがとうございました。私はそれを試し、フィードバックを返します。ソーリン –
記事は本当に便利でした、ありがとう!それは働いた:) –