私はMixare AR SDK for iOSで作業しています。問題のバグを解決する必要があります。その1つはPOIのビューがタップされたときのPOIの情報を表示することです。UIView hitTest:withEvent:and pointInside:withEvent
プレリュード:
Mixareは、MarkerViewビューがPOIをgeolocate画面の周囲を移動しているに配置されMarkerViewビュー内のオーバーレイのUIViewを有し、それぞれが2つのサブビュー、UIImageViewとUILabelを有しています。
問題:
ここで、例えば、画面3個の可視のPOIが存在するので、オーバーレイサブビューとして3 MarkerViewがあります。オーバーレイ内のどこかをタッチすると、ランダムPOIに関連付けられた情報ビューが表示されます。
希望:
私は関連するPOIの情報は、ユーザーがMarkerView
レッツ仕事をタップしたときにのみ表示されていることほしいです。私はMarkerViewはUIViewのを継承しhitTestを実装していることがわかりました:withEvent
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
viewTouched = (MarkerView*)[super hitTest:point withEvent:event];
return self;
}
私はブレークポイントを入れてきたし、hitTestがそれぞれ見えMarkerViewに1回呼び出さが、私はそれで動作することはできませんのでloadedViewは常にnullであるが、 withEvent:私はヒットポイントがpointInsideを実装MarkerViewフレームの内側にあるかどうかを確認しようとしたこのよう
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
NSLog(@"ClassName: %@", [[self class] description]);
NSLog(@"Point Inside: %f, %f", point.x, point.y);
NSLog(@"Frame x: %f y: %f widht:%f height:%f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
if (CGRectContainsPoint(self.frame, point))
return YES;
else
return NO;
return YES;
}
によりしかし、この関数は常に私がMarkerViewに触れた場合でも、NOを返します。私がログを調べると、XとYポイントの値が負の値を持つことがあり、ビューの幅と高さがMarkerViewフレームの初期化時に設定した100 x 150ではなく0.00022またはそれ以下であることがわかりました。
ここでは、クラス名、ポイント、およびMarkerViewフレームの値を確認できるログを抽出します。
ClassName: MarkerView
2011-12-29 13:20:32.679 paisromanico[2996:707] Point Inside: 105.224899, 49.049023
2011-12-29 13:20:32.683 paisromanico[2996:707] Frame x: 187.568573 y: 245.735138 widht:0.021862 height:0.016427
私はこの問題で非常に迷っていますので、どんな援助も歓迎されます。任意の助けを事前に感謝を提供し、私はこのレンガについて申し訳ありません:(
編集:withEvent:またはpointInside:withEvent、問題がある
最後に問題がhitTestではないことを、私を見つけましたDISTANDEに基づいたスケーリングのためのMarkerViewに適用されるCGTransformを使用し、ビューを回転させると、これに関連するコードをコメントすると、Mixare AR SDKはうまく動作します。つまり、マーカーに触れると情報ビューが正しく表示されます
私はこの問題を解決しなかったが、AugmentedViewController.mのCGTransform関連のコードを削除するパッチを適用した。class - (void)upda teLocations:(NSTimer *)timer function
- (void)updateLocations:(NSTimer *)timer {
//update locations!
if (!ar_coordinateViews || ar_coordinateViews.count == 0) {
return;
}
int index = 0;
NSMutableArray * radarPointValues= [[NSMutableArray alloc]initWithCapacity:[ar_coordinates count]];
for (PoiItem *item in ar_coordinates) {
MarkerView *viewToDraw = [ar_coordinateViews objectAtIndex:index];
viewToDraw.tag = index;
if ([self viewportContainsCoordinate:item]) {
CGPoint loc = [self pointInView:ar_overlayView forCoordinate:item];
CGFloat scaleFactor = 1.5;
if (self.scaleViewsBasedOnDistance) {
scaleFactor = 1.0 - self.minimumScaleFactor * (item.radialDistance/self.maximumScaleDistance);
}
float width = viewToDraw.bounds.size.width ;//* scaleFactor;
float height = viewToDraw.bounds.size.height; // * scaleFactor;
viewToDraw.frame = CGRectMake(loc.x - width/2.0, loc.y-height/2.0, width, height);
/*
CATransform3D transform = CATransform3DIdentity;
//set the scale if it needs it.
if (self.scaleViewsBasedOnDistance) {
//scale the perspective transform if we have one.
transform = CATransform3DScale(transform, scaleFactor, scaleFactor, scaleFactor);
}
if (self.rotateViewsBasedOnPerspective) {
transform.m34 = 1.0/300.0;
double itemAzimuth = item.azimuth;
double centerAzimuth = self.centerCoordinate.azimuth;
if (itemAzimuth - centerAzimuth > M_PI) centerAzimuth += 2*M_PI;
if (itemAzimuth - centerAzimuth < -M_PI) itemAzimuth += 2*M_PI;
double angleDifference = itemAzimuth - centerAzimuth;
transform = CATransform3DRotate(transform, self.maximumRotationAngle * angleDifference/(VIEWPORT_HEIGHT_RADIANS/2.0) , 0, 1, 0);
}
viewToDraw.layer.transform = transform;
*/
//if we don't have a superview, set it up.
if (!(viewToDraw.superview)) {
[ar_overlayView addSubview:viewToDraw];
[ar_overlayView sendSubviewToBack:viewToDraw];
}
} else {
[viewToDraw removeFromSuperview];
viewToDraw.transform = CGAffineTransformIdentity;
}
[radarPointValues addObject:item];
index++;
}
float radius = [[[NSUserDefaults standardUserDefaults] objectForKey:@"radius"] floatValue];
if(radius <= 0 || radius > 100){
radius = 5.0;
}
radarView.pois = radarPointValues;
radarView.radius = radius;
[radarView setNeedsDisplay];
[radarPointValues release];
}
どのCoreGrapicsまたはUIのエキスパートからも、この問題についての彼の見解を得ることができますか?
[よくある質問](http://stackoverflow.com/faq)をご覧ください。 –