【发布时间】:2016-04-05 10:18:29
【问题描述】:
我一直在使用这个库在 iOS 上试验增强现实:https://github.com/promet/PRAugmentedReality
我添加了另一个名为“POIDetails”的 xib,用于显示我的兴趣点的详细信息。我通过这段代码添加了一个返回相机屏幕的按钮:
[self dismissViewControllerAnimated:self completion:nil];
但是当我返回 AR 屏幕时,POI 图像变得巨大。
我尝试将高度约束设置为 50,将纵横比设置为 1:1,但这并没有起到任何作用。我尝试像这样使用 sizeThatFits:
[myPOI sizeThatFits:CGSizeMake(50, 50)];
但它也没有用。在看到没有区别后,我将我在图像大小上所做的一切都放回去了。
您可以在下面看到之前和之后的图片以及用于下载我的项目的 google drive 链接。我怎样才能确保这张图片不会超出 50 像素的高度?
链接:https://drive.google.com/file/d/0B-cDfWHidgvcVVFRNll0OVR2UTA/view?usp=sharing
这是我的 ARObject.m 文件
#import "ARObject.h"
#import "POIDetails.h"
@interface ARObject ()
@end
@implementation ARObject
@synthesize arTitle, distance;
- (id)initWithId:(int)newId
title:(NSString*)newTitle
coordinates:(CLLocationCoordinate2D)newCoordinates
andCurrentLocation:(CLLocationCoordinate2D)currLoc
{
self = [super init];
if (self) {
arId = newId;
arTitle = [[NSString alloc] initWithString:newTitle];
lat = newCoordinates.latitude;
lon = newCoordinates.longitude;
distance = @([self calculateDistanceFrom:currLoc]);
[self.view setTag:newId];
}
return self;
}
-(double)calculateDistanceFrom:(CLLocationCoordinate2D)user_loc_coord
{
CLLocationCoordinate2D object_loc_coord = CLLocationCoordinate2DMake(lat, lon);
CLLocation *object_location = [[CLLocation alloc] initWithLatitude:object_loc_coord.latitude
longitude:object_loc_coord.longitude];
CLLocation *user_location = [[CLLocation alloc] initWithLatitude:user_loc_coord.latitude
longitude:user_loc_coord.longitude];
return [object_location distanceFromLocation:user_location];
}
-(NSString*)getDistanceLabelText
{
if (distance.doubleValue > POINT_ONE_MILE_METERS)
return [NSString stringWithFormat:@"%.2f mi", distance.doubleValue*METERS_TO_MILES];
else return [NSString stringWithFormat:@"%.0f ft", distance.doubleValue*METERS_TO_FEET];
}
- (NSDictionary*)getARObjectData
{
NSArray *keys = @[@"id",@"title", @"latitude", @"longitude", @"distance"];
NSArray *values = @[@(arId),
arTitle,
@(lat),
@(lon),
distance];
return [NSDictionary dictionaryWithObjects:values forKeys:keys];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[titleL setText:arTitle];
[distanceL setText:[self getDistanceLabelText]];
}
-(void)myPOITapping:(UIGestureRecognizer *)recognizer
{
NSLog(@"image click");
POIDetails *poiDetails = [[POIDetails alloc] initWithNibName:@"POIDetails" bundle:nil]; // constructor
[self presentViewController:poiDetails animated:YES completion:nil];
}
// viewDidLoad wasn't in the library, timur added this method
- (void)viewDidLoad {
myPOI.contentMode = UIViewContentModeScaleToFill;
myPOI.translatesAutoresizingMaskIntoConstraints=YES;
[myPOI setUserInteractionEnabled:YES];
UITapGestureRecognizer *myPOITap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myPOITapping:)];
[myPOITap setNumberOfTapsRequired:1];
[myPOI addGestureRecognizer:myPOITap];
[self.view addSubview:myPOI];
}
#pragma mark -- OO Methods
- (NSString *)description {
return [NSString stringWithFormat:@"ARObject %d - %@ - lat: %f - lon: %f - distance: %@",
arId, arTitle, lat, lon, distance];
}
@end
编辑:
我在我的 ARObject.m 文件的 viewDidLoad 函数中添加了以下代码,它似乎将图像保持在设定的分辨率。
myPOI.contentMode = UIViewContentModeScaleToFill; myPOI.translatesAutoresizingMaskIntoConstraints=YES;
但我的距离标签仍然存在问题。我将顶部和底部间距约束设置为最近的邻居,标签现在是一半,但仍与我的兴趣点图像分开,如下所示:
【问题讨论】:
标签: ios objective-c swift uiimageview augmented-reality