私のアプリにはいくつかのボタンが付いています。各ボタンは別々のビューを開きます。各ビューで、デバイスを横長にするとヘルプビューが表示されます。私がiPhoneをテーブルの上に置くように置くと(私はeplainの方がわかりません...)、アプリケーションはそのビューから抜け出し、最初のビューに戻ります。ホーム。 は、ここに私のコードです:iPhoneの回転を傍受する方法
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification"
object:nil];
[self performSelector:@selector (ritardo) withObject:nil afterDelay:5.0f];
}
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIInterfaceOrientationPortrait)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation
== UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
-(void) ritardo {
ruota.image = [UIImage imageNamed:@"RuotaPerAiuto.png"];
}
- (void)viewDidUnload
{
[self setPortraitView:nil];
[self setLandscapeView:nil];
[self setRuota:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end
こんにちはあなたは私に役立つことを願って
EDIT: は私が修正 - (ボイド)orientationChanged:(NSNotification *)オブジェクトを{このように:
-(void)orientationChanged:(NSNotification *)object{
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if (deviceOrientation == UIDeviceOrientationFaceUp)// || deviceOrientation ==
UIDeviceOrientationFaceDown)
{
return;
}
if (deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation ==
UIInterfaceOrientationPortraitUpsideDown)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.portraitView;
}
else
if (deviceOrientation == UIInterfaceOrientationLandscapeLeft || deviceOrientation ==
UIInterfaceOrientationLandscapeRight)
{
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.view = self.landscapeView;
}
[UIView commitAnimations];
[self dismissModalViewControllerAnimated:NO];
}
今、私が肖像画になっていて、iPhoneをfaceUpポジションにしてもうまくいけば。しかし、私がfaceUpから肖像画に姿を変えると、それは家に戻ります。
ありがとうございました。私はちょうどあなたの提案に応じてorientationChangedメソッドを変更しましたが、それはまだ同じです。たぶん私は私が扱いたいと思うiPhoneの位置を正確に説明することはできません:それはこのような何かをfaceUpすることができますか? – Enzoses
今それは素晴らしい、ありがとう! – Enzoses
いいえ...私はあまりにも早く話しました...今、iPhoneの位置がfaceUpからPortraitに戻るときにHomeに戻ります:(私はif(deviceOrientation == UIDeviceOrientationFaceUp)//を追加してorientationChangedメソッドを変更しました。 || deviceOrientation == UIDeviceOrientationFaceDown){return;} – Enzoses