摇动以模式方式打开视图

发布于 2024-08-30 03:21:52 字数 446 浏览 10 评论 0原文

我的“摇动”工作正常(使用motionEnded),基于Apple的GLPaint代码。当用户摇动设备(运行 3.0 及更高版本)时,我想使用presentModalViewController 以模态方式打开视图控制器。

在我的 appdelegate 中,我收到通知(根据 GLPaint 示例代码):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shakeToOpenHiddenScreen) name:@"shake" object:nil];

在我的 shakeToOpenHiddenScreen 中,我只想以模态方式打开视图“x”,但我不认为我的 appdelegate 会响应 PresentModalViewController。

有办法解决这个问题吗?

I have my 'shake' working fine (using motionEnded), based off of Apple's GLPaint code. When the user shakes the device (running 3.0 and up) I want to open a view controller modally using presentModalViewController.

In my appdelegate I have the notification (as per the GLPaint sample code):

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shakeToOpenHiddenScreen) name:@"shake" object:nil];

In my shakeToOpenHiddenScreen I just want to open view 'x' modally but I don't think that my appdelegate will respond to presentModalViewController.

Is there a way around this?

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

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

发布评论

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

评论(2

胡渣熟男 2024-09-06 03:21:52

要使用presentModalViewController,您必须从UIViewController类或子类中使用它:

例如:
//RootViewController.m
[self.navigationController PresentModalViewController:loginRegView 动画:YES];

您可以通过在应用程序委托中定义导航控制器

//yourApp_comAppDelegate.h
UINavigationController *nav;
...
@property(nonatomic,retain) UINavigationController *nav;

并合成它来

@syntetize nav;    

解决此问题:要使用presentModalViewController,您必须从 UIViewController 类或子类中使用它:

例如:

//RootViewController.m
[self.navigationController presentModalViewController:loginRegView animated:YES];

您可以通过在应用程序委托中定义导航控制器来解决此问题你的应用程序委托:

//yourApp_comAppDelegate.h
UINavigationController *nav;
...
@property(nonatomic,retain) UINavigationController *nav;

合成它

//yourApp_comAppDelegate.m
@synthesize nav;

,现在你可以使用该方法:

//yourApp_comAppDelegate.m
[nav presentModalViewController:yourView animated:YES];

但是,首先你必须将它分配到某个地方,我将在 RootViewController 中进行它

//RootViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
app = (yourApp_comAppDelegate *) [[UIApplication sharedApplication] delegate];
    app.nav = self.navigationController
}

应该可以工作,让我知道:)

To use presentModalViewController you have to use it from a UIViewController class, or subclass:

For example:
//RootViewController.m
[self.navigationController presentModalViewController:loginRegView animated:YES];

You can way around this problem by defining a navigation controller into your app delegate:

//yourApp_comAppDelegate.h
UINavigationController *nav;
...
@property(nonatomic,retain) UINavigationController *nav;

and synthesize it

@syntetize nav;    

To use presentModalViewController you have to use it from a UIViewController class, or subclass:

For example:

//RootViewController.m
[self.navigationController presentModalViewController:loginRegView animated:YES];

You can way around this problem by defining a navigation controller into your app delegate:

//yourApp_comAppDelegate.h
UINavigationController *nav;
...
@property(nonatomic,retain) UINavigationController *nav;

synthesize it

//yourApp_comAppDelegate.m
@synthesize nav;

and now you can use the method:

//yourApp_comAppDelegate.m
[nav presentModalViewController:yourView animated:YES];

but, first you have to assign it somewhere, i will do it in the RootViewController

//RootViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
app = (yourApp_comAppDelegate *) [[UIApplication sharedApplication] delegate];
    app.nav = self.navigationController
}

It should work, let me know :)

深海蓝天 2024-09-06 03:21:52

它是 UIViewController 上的一种方法,因此您应该能够从 appDelegate 访问已保存的视图控制器,或者设置通知来调用一个 (addObserver:someVC)。

“shake”不是标准通知名称,因此应用程序中的其他位置应该有一些代码发布此通知,大概也是从 GLPaint 示例复制的。

It is a method on UIViewController, so you should either have access to a saved view controller from your appDelegate, or else set up the notification to call one (addObserver:someVC).

"shake" isn't a standard notification name, so there should be some code elsewhere in your app that posts this notification, presumably also copied from the GLPaint sample.

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