1

サブビューがビューに追加されたときにトリガーされるデリゲート メソッドを探しています。iOS7マップのコンパスビューが回転を開始するとマップビューに追加されるため、これが必要です(以前は存在せず、非表示にされていません)。ただし、コンパス ビューを操作しようとするとregionWillChangeAnimated、ユーザーがマップを離すまでトリガーされません。

基本的に、次のようなものが必要です: subviewWasAddedsubviewsDidChange、またはそのようなもの。

編集: Daij-Djan の提案を受けて、MPOMapView.m と MPOMapView を作成しました。

#import "MPOMapView.h"

@implementation MPOMapView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)addSubview:(UIView *)view {
    [super addSubview:view];

    [self moveCompass:&view];
}


- (void)moveCompass:(UIView **)view {

    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
        return;
    }

    if(![*view isKindOfClass:NSClassFromString(@"MKCompassView")]) {
        return;
    }

    //Gets here
    NSLog(@"Was the compass");

    float width = (*view).frame.size.width;
    float height = (*view).frame.size.height;

    (*view).frame = CGRectMake(40, self.frame.size.height - 50, width, height);

    //Frame doesn't change
    NSLog(@"Frame should change");
}

@end

メソッドが呼び出されますが、フレームは変更されません。私も試しました:

- (void)addSubview:(UIView *)view {
    [super addSubview:view];

    [self moveCompass:view];
}


- (void)moveCompass:(UIView *)view {

    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
        return;
    }

    if(![view isKindOfClass:NSClassFromString(@"MKCompassView")]) {
        return;
    }

    //Gets here
    NSLog(@"Was the compass");

    float width = view.frame.size.width;
    float height = view.frame.size.height;

    view.frame = CGRectMake(40, self.frame.size.height - 50, width, height);

    //Frame doesn't change
    NSLog(@"Frame should change");
}

しかし、これもうまくいきません。そして最後に....

- (void)addSubview:(UIView *)view {
    [super addSubview:[self movedCompass:view]];
}


- (UIView *)movedCompass:(UIView *)view {

    if([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
        return view;
    }

    if(![view isKindOfClass:NSClassFromString(@"MKCompassView")]) {
        return view;
    }

    //Gets here
    NSLog(@"Was the compass");

    float width = view.frame.size.width;
    float height = view.frame.size.height;

    view.frame = CGRectMake(40, self.frame.size.height - 50, width, height);

    //Frame doesn't change
    NSLog(@"Frame should change");

    return view;
}

どちらも機能しません

4

3 に答える 3

2

Daij-Djan が正解を投稿しました。彼の功績です。

これは、コードが多すぎると感じていることの改善にすぎません。

- (void)layoutSubviews 
{
    [super layoutSubviews];

    for(id view in self.subviews) 
    {
        if([view isKindOfClass:NSClassFromString(@"MKCompassView")]) 
            [self moveCompass:view]];
    }
}

- (void)moveCompass:(UIView *)view 
{
    //change compass frame as shown by Daij-Djan
}
于 2013-12-04T07:55:35.083 に答える
0

それが機能するかどうかはわかりませんcameraが、プロパティを持つmapview で Key Value Observing を使用してみてくださいheading

于 2013-10-02T21:06:32.370 に答える