1

それについて多くの投稿があることは知っていますが、最善の解決策を見つけることができません。

横長モードで水平方向に伸びる多くの scrollViews を含む「ホルダー」ビュー (UIView) があります。各 scrollview には、垂直方向にスクロールされるビューを含む画像が含まれています。繰り返しますが、すべてがランドスケープです。

私が望むのは、ポートレートモードに回転すると、すべてを含む「ホルダー」ビューは同じままです。つまり、列になり、スクロールビューが回転し、スクロールが水平になりますが、スクロールビュー (画像を含むビュー) のコンテンツが回転します。

UIView 子クラス (「ホルダー」ビュー用) を作成し、次のメソッドを配置しようとしました。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

同じように、「ホルダー」ビューにあるサブビューを処理したいと思っていましたが、うまくいきません。最善の方法は何ですか?ありがとう。

4

1 に答える 1

1

サポートされている方向が必要なものであることを設定し、UIDevice方向の変更を観察して、他の方向を手動で処理することができます。ここに例があります:

#import "ViewController.h"

@interface ViewController ()

- (void)deviceDidRotate:(NSNotification *)notification;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(deviceDidRotate:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

#pragma mark - Private methods

- (void)deviceDidRotate:(NSNotification *)notification {

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    /* Handle manually the rotation
       For instance, apply a transform to a UIView:
       CGAffineTransform transform = CGAffineTransformMakeRotation(radians);
       self.aView.transform = transform; */
}

@end
于 2012-10-11T10:15:18.343 に答える