如何检测用户何时在停用时再次运行WP7 XNA应用程序?(How to detect when user has run WP7 XNA Application again while deactivated?)
我在C#中使用XNA 4.0编写了一个Windows Phone 7游戏。
如果用户执行以下操作,似乎可以避免Game.OnExiting方法:
- 在Windows Phone OS中通过Tile启动游戏。
- 在游戏过程中,按下WINDOWS按钮离开游戏(导致调用Game.OnDeactivated而不是Game.OnExiting )。
- 用户通过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:
- Starts game through Tile in Windows Phone OS.
- During gameplay, press the WINDOWS button to leave the game (resulting in a call to Game.OnDeactivated but not Game.OnExiting).
- 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
最满意答案
您可以使用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.'
相关问答
更多-
边界UITextView(Bordered UITextView)[2021-08-07]
#import.... // typically inside of the -(void) viewDidLoad method self.yourUITextView.layer.borderWidth = 5.0f; self.yourUITextView.layer.borderColor = [[UIColor grayColor] CGColor]; #import .... // ... -
占位符在UITextView(Placeholder in UITextView)[2021-12-03]
我对bcd的解决方案进行了一些细微的修改,允许从Xib文件进行初始化,文本包装和维护背景颜色。 希望能拯救别人的麻烦。 UIPlaceHolderTextView.h: #importIB_DESIGNABLE @interface UIPlaceHolderTextView : UITextView @property (nonatomic, retain) IBInspectable NSString *placeholder; @property ... -
如何在可变高度的UITableViewCell中使用UITextView?(How to use UITextView in UITableViewCell with variable height?)[2023-02-09]
据我所知,设置表格单元格高度的唯一方法是通过委托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 ...
-
UITextView Alternative(UITextView Alternative)[2022-10-27]
您可以使用包含所需所有属性的NSDictionary构建NSAttributedString: NSAttributedString* attString = [[NSAttributedString alloc] initWithString: @"Desired effect to be written by code" attributes: (NSDictionary*)attributes]; 或者使用它的可变子类NSMut ... -
UITextView autoSize(UITextView autoSize)[2023-04-11]
使用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 ...