UINavigation 控制器 UIViewController 和 UItoolbar 作为子视图问题

发布于 2024-12-01 12:23:58 字数 3092 浏览 1 评论 0原文

嘿伙计们,我正在尝试离开增强现实并转到导航控制器的下一个视图控制器

,代码来自 ARKit 演示,我只是以编程方式添加了一个 UIToolbar 作为子视图,其中有一个操作按钮..我希望这个按钮导致我现有的导航控制器的下一个视图控制器。操作 takePicture: 被执行,因为我有一条 NSLog 消息,但未添加新的视图控制器

这是 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

非常感谢

Hey guys i am trying to leave the augmented reality and go to the next view controller of to my navigation controller

the code is from ARKit demo and i just added programmatically a UIToolbar as a subview which has an action button ..I want this button to lead to the next view controller of my existing navigation controller. the action takePicture: is executed as i have an NSLog message but the new viewcontroller is not added

this is the code of the 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

this is the code of the 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

Thank you so much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你如我软肋 2024-12-08 12:23:58

我对 ARKit 没有经验,但cameraController是导航控制器堆栈的一部分吗?当你这样做时释放它,你可能会抛弃一些东西。作为一个测试,尝试注释掉释放cameraController的代码行,看看它是否会影响这一点。

另外,FWIW 我希望您用来设置工具栏的代码位于 viewDidLoad 中,而不是 viewDidAppear 中。

I'm not experienced with ARKit, but is cameraController part of the navigation controller's stack? By releasing it when you do you might be throwing things off. Just as a test, try commenting out the line of code that releases cameraController to see if it's impacting this.

Also, FWIW I would have expected the code that your using to set up the toolbar to be in viewDidLoad, not viewDidAppear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文