嘿伙计们我正试图离开增强现实并转到我的导航控制器的下一个视图控制器
代码来自ARKit演示,我只是以编程方式添加了一个UIToolbar作为子视图,它有一个动作按钮..我希望这个按钮通向我现有导航控制器的下一个视图控制器。动作takePicture:执行,因为我有一个NSLog消息,但没有添加新的viewcontroller
这是ARGeoViewController.h的代码
#import <Foundation/Foundation.h>
#import "ARViewController.h"
#import "AfterARViewController.h"
@interface ARGeoViewController : ARViewController {
CLLocation *centerLocation;
AfterARViewController *afterARViewController;
}
@property (nonatomic, retain) CLLocation *centerLocation;
- (IBAction)takePicture:(id)sender;
@property (nonatomic, retain) AfterARViewController *afterARViewController;
@end
这是ARGeoViewController.m的代码
#import "ARGeoViewController.h"
#import "ARGeoCoordinate.h"
#import "ARViewController.h"
@implementation ARGeoViewController
@synthesize centerLocation;
@synthesize afterARViewController;
- (void)setCenterLocation:(CLLocation *)newLocation {
[centerLocation release];
centerLocation = [newLocation retain];
for (ARGeoCoordinate *geoLocation in self.coordinates) {
if ([geoLocation isKindOfClass:[ARGeoCoordinate class]]) {
[geoLocation calibrateUsingOrigin:centerLocation];
if (geoLocation.radialDistance > self.maximumScaleDistance) {
self.maximumScaleDistance = geoLocation.radialDistance;
}
}
}
}
-(void)viewWillAppear:(BOOL)animated{
UIToolbar *toolbar = [UIToolbar new];
toolbar.barStyle = UIBarStyleBlackTranslucent;
// create a bordered style button with custom title
UIBarButtonItem *playItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:@selector(takePicture:)] autorelease];
NSArray *items = [NSArray arrayWithObjects:
playItem,
nil];
toolbar.items = items;
// size up the toolbar and set its frame
// please not that it will work only for views without Navigation toolbars.
[toolbar sizeToFit];
CGFloat toolbarHeight = [toolbar frame].size.height;
CGRect mainViewBounds = self.view.bounds;
[toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
CGRectGetWidth(mainViewBounds),
toolbarHeight)];
[self.view addSubview:toolbar];
}
- (IBAction)takePicture:(id)sender
{
NSLog(@"takepicture");
if(self.afterARViewController == nil)
{
AfterARViewController *afterARController = [[AfterARViewController alloc]
initWithNibName:@"AfterARViewController" bundle:[NSBundle mainBundle]];
self.afterARViewController = afterARController;
[afterARController release];
[cameraController release];
}
[self.navigationController pushViewController:self.afterARViewController animated:YES];
}
@end
非常感谢
答案 0 :(得分:0)
我对ARKit没有经验,但是CameraController是导航控制器堆栈的一部分吗?通过释放它,你可能会扔掉它。就像测试一样,尝试注释掉释放cameraController的代码行,看它是否会影响它。
另外,FWIW我原本期望你用来设置工具栏的代码在viewDidLoad中,而不是viewDidAppear。