2013-10-10 29 views
1

我必須根據當前位置將箭頭指向特定位置。爲此,我使用didUpdateHeading委託方法獲取真正的標題值。箭頭指向iPad中的特定位置

在iPhone(肖像模式)中,箭頭圖像顯示完美。但在iPad中它沒有正確顯示。它處於橫向模式。

我使用找到軸承距離的代碼,

- (void)UpdateCompass:(NSNotification *)notification 
{ 
    CLLocation *newLocation = [[CLLocation alloc] initWithLatitude:m_nLatitude longitude:m_nLongitude]; 
    CLLocation* target = [[CLLocation alloc] initWithLatitude:questionLatitude longitude:questionLangitude ]; 
    _latestBearing = [self getHeadingForDirectionFromCoordinate:newLocation.coordinate toCoordinate:target.coordinate]; 
    CGFloat degrees = _latestBearing - m_CLHeading.magneticHeading; 
    CGAffineTransform cgaRotate = CGAffineTransformMakeRotation([self degreesToRadians:degrees]); 
    m_arrowImage.transform = cgaRotate; 
} 

- (double)degreesToRadians:(double)degrees 
{ 
    return degrees * M_PI/180.0; 
} 

- (double)radiansToDegrees:(double)radians 
{ 
    return radians * 180.0/M_PI; 
} 

- (double)getHeadingForDirectionFromCoordinate:(CLLocationCoordinate2D)fromLoc toCoordinate:(CLLocationCoordinate2D)toLoc 
{ 
    double lat1 = [self degreesToRadians:fromLoc.latitude]; 
    double lon1 = [self degreesToRadians:fromLoc.longitude]; 
    double lat2 = [self degreesToRadians:toLoc.latitude]; 
    double lon2 = [self degreesToRadians:toLoc.longitude]; 
    double dLon = lon2 - lon1; 
    double y = sin(dLon) * cos(lat2); 
    double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon); 
    double radiansBearing = atan2(y, x); 

    if(radiansBearing < 0.0) 
     radiansBearing += 2*M_PI; 
     return [self radiansToDegrees:radiansBearing]; 
} 

我怎樣才能使這項工作爲iPad?

回答

0

檢查設備是iPad或iPhone,並編寫代碼相應

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
{ 
    // The device is an iPad running iPhone 3.2 or later. 
} 
else 
{ 
    // The device is an iPhone or iPod touch. 
} 
+0

那我也沒有。但上面的代碼在iPad中不起作用。我正在尋找一個在iPad上工作的代碼。 – Bharathi

+0

你可以把任何屏幕截圖如何在iPhone和iPad顯示不同 – kaustubh