하위 뷰를 뷰에 추가 할 때 트리거되는 대리자 메서드를 찾고 있습니다. iOS7지도의 나침반보기가 회전하기 시작할 때 Mapview에 추가되기 때문에 필요합니다 (이전에 표시되지 않고 숨김 상태가 아닙니다). 그러나 regionWillChangeAnimated
에서 나침반보기를 조작하려고 시도하면 사용자가지도를 놓을 때까지 트리거되지 않습니다.subviewsDidChange 대리자 메서드를 찾고
기본적으로 나는 subviewWasAdded
, subviewsDidChange
또는 그와 비슷한 내용이 필요합니다.
EDIT : 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;
}
는 그러한 위임이없는 중 하나
@Mike_V 당신은 당신의 앱이 MKCompassView private 클래스 그런 식으로 액세스, 코드를 통해 허용 얻을 관리 했습니까? 공공 응용 프로그램에 대해 동일한 작업을 수행해야합니다. – pnizzle