首页 \ 问答 \ 如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)

如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)

我在C#中使用XNA 4.0编写了一个Windows Phone 7游戏。

如果用户执行以下操作,似乎可以避免Game.OnExiting方法:

  1. 在Windows Phone OS中通过Tile启动游戏。
  2. 在游戏过程中,按下WINDOWS按钮离开游戏(导致调用Game.OnDeactivated而不是Game.OnExiting )。
  3. 用户通过Windows Phone OS中的Tile再次启动游戏。

我已经阅读了很多关于WP7应用程序生命周期的内容,但是在用户连续两次运行相同应用程序的情况下无法找到任何内容。

我有一些逻辑,只有在游戏关闭的情况下被调用才有意义,并且重要的是它不会错过(例如上面的情况)。 我无法在OnDeactivated调用它,因为它会导致糟糕的用户体验。

这是有问题的代码(在我的Game类的实现中找到):

protected override void OnExiting(object sender, EventArgs args)
{
    // This is what is getting missed!
    ForceSave();

    base.OnExiting(sender, args);
}

protected override void OnDeactivated(object sender, EventArgs args)
{
    base.OnDeactivated(sender, args);

    // I don't want to put ForceSave here because it will get called even if the user is not exiting the game.

    ...
}

protected override void OnActivated(object sender, EventArgs args)
{
    base.OnActivated(sender, args);

    ...
}

I have a Windows Phone 7 game written with XNA 4.0 in C#.

It seems that the Game.OnExiting method can be avoided if the user does the following:

  1. Starts game through Tile in Windows Phone OS.
  2. During gameplay, press the WINDOWS button to leave the game (resulting in a call to Game.OnDeactivated but not Game.OnExiting).
  3. User starts the game again through the Tile in Windows Phone OS.

I have read much on the WP7 App Lifecycle, but haven't been able to find anything touching on this case where the user runs the same app twice in a row.

I have some logic that only makes sense to be called if the game is shutting down, and is also important that it isn't missed (such as in the case above). I cannot call it in OnDeactivated because it would cause a poor user experience.

Here is the code in question (found inside my implementation of the Game class):

protected override void OnExiting(object sender, EventArgs args)
{
    // This is what is getting missed!
    ForceSave();

    base.OnExiting(sender, args);
}

protected override void OnDeactivated(object sender, EventArgs args)
{
    base.OnDeactivated(sender, args);

    // I don't want to put ForceSave here because it will get called even if the user is not exiting the game.

    ...
}

protected override void OnActivated(object sender, EventArgs args)
{
    base.OnActivated(sender, args);

    ...
}

原文:https://stackoverflow.com/questions/20591846
更新时间:2022-01-30 17:01

最满意答案

您可以使用NSString中的内置字符串连接方法来实现此目的:

NSString *myString = @"sad";
textView.text = [NSString stringWithFormat:@"I am feeling %@.", myString];

// textView.text is now 'I am feeling sad.'

You can use the built-in string concatenation method in NSString to achieve this:

NSString *myString = @"sad";
textView.text = [NSString stringWithFormat:@"I am feeling %@.", myString];

// textView.text is now 'I am feeling sad.'

相关问答

更多
  • #import .... // typically inside of the -(void) viewDidLoad method self.yourUITextView.layer.borderWidth = 5.0f; self.yourUITextView.layer.borderColor = [[UIColor grayColor] CGColor]; #import .... // ...
  • 我对bcd的解决方案进行了一些细微的修改,允许从Xib文件进行初始化,文本包装和维护背景颜色。 希望能拯救别人的麻烦。 UIPlaceHolderTextView.h: #import IB_DESIGNABLE @interface UIPlaceHolderTextView : UITextView @property (nonatomic, retain) IBInspectable NSString *placeholder; @property ...
  • 据我所知,设置表格单元格高度的唯一方法是通过委托heightForRowAtIndexPath:方法。 要调用此方法,您可以在表上调用reloadData,但我不确定这对您正在编辑的UITextView会产生什么影响。 值得一试。 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } 要计算返回值,您需要根据当前输入计算高度,并同时展开文 ...
  • 这不仅仅是一个干净的解决方案,而是一个黑客攻击。 您可以尝试隐藏并显示键盘(即resignFirstResponder ,更改返回键样式和becomeFirstResponder )。 但它会产生一个奇怪的动画。 为避免此故障,您应该能够防止屏幕刷新。 顺便说一句,在这种方法结束时,你会回答YES或NO ? More than a clean solution, this is a bit of a hack. You could try to hide and show the keyboard (i.e ...
  • rmaddy是对的, UILabel是要走的路。 您需要隐藏“更多”按钮,并在用户点按时显示隐藏(或更少?)按钮和标签。 您还需要更改行的高度以适应新内容。 要找到表格行的适当高度,请使用[UILabel sizeToFit]或[UILabel sizeThatFits] 。 要为行的高度变化设置动画,请查看选中时是否可以在UITableViewCell上设置高度更改动画? rmaddy is right, UILabel is the way to go. You need to hide the Mor ...
  • 您可以使用包含所需所有属性的NSDictionary构建NSAttributedString: NSAttributedString* attString = [[NSAttributedString alloc] initWithString: @"Desired effect to be written by code" attributes: (NSDictionary*)attributes]; 或者使用它的可变子类NSMut ...
  • 使用UILabel并设置以下属性: adjustsFontSizeToFitWidth = YES; minimumFontSize = [UIFont systemFontofSize: 10]; // or whatever suits your app numberOfLines = 2; In case anyone else comes across this issue, I found the answer for this here: http://www.11pixel.com/blo ...
  • 您可以使用NSString中的内置字符串连接方法来实现此目的: NSString *myString = @"sad"; textView.text = [NSString stringWithFormat:@"I am feeling %@.", myString]; // textView.text is now 'I am feeling sad.' You can use the built-in string concatenation method in NSString to achiev ...
  • 使用tableview,然后在每行中放置文本字段,以便如果文本字段限制达到最大长度,则下一行文本字段将成为第一响应者。 当用户单击“保存”然后从所有文本字段中读取数据,然后将其保存到您想要的位置。 但我遇到的唯一问题是当用户过去一些数据时,如果过去的数据大于文本字段的最大长度,我无法在下一个文本字段中显示该数据。 希望这能帮到别人。 use a tableview and then place text field in each row such that if the text field limit ...
  • 我会尝试更改表视图的内容大小: [textView setContentSize:CGSizeMake(width, height)]; 设置宽度和高度,以便整个文本视图适合该文本视图。 还要检查文本视图中是否启用了滚动; 如果不是那么设置它: textView.scrollEnabled = YES; 希望能帮助到你! ; d I would try to change the table view content size: [textView setContentSize:CGSizeMake(w ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)