サブビューがビューに追加されたときにトリガーされるデリゲート メソッドを探しています。iOS7マップのコンパスビューが回転を開始するとマップビューに追加されるため、これが必要です(以前は存在せず、非表示にされていません)。ただし、コンパス ビューを操作しようとするとregionWillChangeAnimated
、ユーザーがマップを離すまでトリガーされません。
基本的に、次のようなものが必要です:
subviewWasAdded
、subviewsDidChange
、またはそのようなもの。
編集: 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;
}
どちらも機能しません