1

最近、自分のアプリで非常に奇妙な動作をしていることに気付きました。ビューのフレームを設定すると、原点が入力した値の 2 倍であるかのように動作します。他のビューは影響を受けず、影響を受けるビューの幅と高さも影響を受けません。このようなことを以前に見たり聞いたりした人はいますか?

編集:

これは私のカスタム init メソッドのコードで、何らかの形で問題を引き起こしているようですが、その理由を特定することはできません。

if ((self = [super initWithFrame:frame])) {
        self.backgroundColor = [UIColor clearColor];
        self.controller = aController;
        self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
        UIView *centerView = [[UIView alloc] initWithFrame:frame];
        [self addSubview:centerView];
        UIToolbar *navBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 44)];
        NSMutableArray *array = [[NSMutableArray alloc] init];
        UIBarButtonItem *item = item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(closeClicked:)];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithTitle:@"Title" style:UIBarButtonItemStylePlain target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        [array addObject:item];
        item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];
        [array addObject:item];
        [navBar setItems:array];
        [centerView addSubview:navBar];
        centerView.clipsToBounds = YES;
        centerView.opaque = TRUE;
        centerView.alpha = 1.0;
        centerView.backgroundColor = [UIColor whiteColor];
        [self addSubview:centerView];
    }
    return self;
}
4

1 に答える 1

2

以前、xibs でこのような奇妙なことを経験したことがあります。これは通常、xib が内部で iPad xib ではなく iPhone xib としてラベル付けされていることが原因です。通常、xib をゼロから再作成する必要があります。

ユニバーサルアプリですか?View Controllerが初期化されたときにiPad xibがロードされていることを確認してください。

コードを追加した後に編集します。

問題は、あなたが渡しているフレームにあるようです.initメソッドが(10,10,w,h)のフレームを渡されている場合、centerViewを作成すると、彼のしたがって、ここで囲んでいるビューが 10,10 にあり、センタービューが囲んでいるビュー内で 10,10 にある場合、センタービューはより大きなスコープ内で 20,20 にあるように見えます。

x、y として 0,0 を使用して centerView を作成する必要があります。

CGRect centerViewFrame = CGRectMake(0, 0, frame.size.width, frame.size.height);
UIView *centerView = [[UIView alloc] centerViewFrame];
于 2011-02-03T03:40:22.850 に答える