Tag: uiviewcontroller

Swift – 使用NSUserDefaults保存高分

我正在用Swift做游戏。 我想用NSUserDefaults保存用户高分。 我知道如何在我的AppDelegate文件中创build一个新的NSUserDefaultsvariables: let highscore: NSUserDefaults = NSUserDefaults.standardUserDefaults() 但是,我如何设置/得到这个在我的视图控制器?

在滚动UIScrollView期间UILabel更新停止

我有一个scrollView与imageView里面。 scrollView是superView的子视图,而imageView是scrollView的子scrollView 。 我还有一个标签(在超级视图级别),每毫秒从NSTimer接收文本属性的更新值。 问题是:在滚动期间,标签停止显示更新。 当滚动结束时,标签上的更新重新开始。 当更新重新启动它们是正确的; 这意味着label.text值按预期更新,但在滚动时,更新显示会在某处被覆盖。 不pipe是否滚动,我都想在标签上显示更新。 以下是如何实现标签更新: – (void)startElapsedTimeTimer { [self setStartTime:CFAbsoluteTimeGetCurrent()]; NSTimer *elapsedTimeTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(updateElapsedTimeLabel) repeats:YES]; } – (void)updateElapsedTimeLabel { CFTimeInterval currentTime = CFAbsoluteTimeGetCurrent(); float theTime = currentTime – startTime; elapsedTimeLabel.text = [NSString stringWithFormat:@"%1.2f sec.", theTime]; } 感谢您的帮助。

shouldAutorotateToInterfaceOrientation不起作用

我一直在肖像模式下写我的通用应用程序,现在约15笔尖文件,许多viewCotnrollers,我想实现shouldAutorotateToInterfaceOrientation并devise一些屏幕在横向模式。 join: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } 到我的所有viewControllers,不做的工作。 在debugging期间,我看到这个方法被调用,但它不会工作! 不在模拟器中,不在设备中,不在Iphone中,不在Ipad中! 我在论坛中search了一些答案,并看到一些build议使用: – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ); } 也没有工作, 添加: [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 和 [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; 到我的viewDidLoad和viewDidUnload分别没有任何工作。 我迷路了..任何帮助都行! 只是一个更多的信息.​​..所有我的意见是typesUIControl,因为我需要TuchUpInside工作。 Appriciate你的帮助。

呈现和解除模态视图控制器

任何人都可以给我的示例代码,我可以用来首先提出一个模式的视图控制器,然后解雇它? 这是我一直在尝试的: NSLog(@“%@”,blue.modalViewController); [蓝色presentModalViewController:红色animation:是]; NSLog(@“%@”,blue.modalViewController); [blue dismissModalViewControllerAnimated:YES]; NSLog(@“%@”,blue.modalViewController); 这段代码在viewDidLoad中(“blue”和“red”都是UIViewController的子类)。 我希望我会显示红色的视图,然后立即隐藏它,用一些animation。 然而,这段代码只提供了模态视图,并没有消除它。 任何想法? 第一个日志显示“空”,而另外两个日志显示<RedViewController:0x3d21bf0> 另一点是,如果我把这个代码放在applicationDidFinishLaunching中:红色的视图根本不会出现,所有的日志都会变成“null”

使一个button在所有视图控制器中保持不变

我想在我的应用程序的右下angular有一个持久button。 在所有视图转换期间,button应保持静态。 我无法决定添加button的视图。 我知道这个button应该存储在AppDelegate中,但是我不知道将其他视图添加到除窗口之外是否合适。 将其添加到窗口的一个缺点是,当有一个应用程序在后台运行(即电话),添加的状态栏填充将按下窗口。 一般来说,将它添加到窗口似乎是一个hacky解决scheme – 任何想法?

显示主标签栏控制器之前的login视图控制器

我正在创build一个需要login的标签栏控制器的iPad应用程序。 所以在启动时,我想显示一个LoginViewController,如果login成功,然后显示标签栏控制器。 这是我如何实现一个初始testing版本(省略了一些典型的标题等)… AppDelegate.h: @interface AppDelegate_Pad : NSObject <UIApplicationDelegate, LoginViewControllerDelegate> { UIWindow *window; UITabBarController *tabBarController; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; @end AppDelegate.m: @implementation AppDelegate_Pad @synthesize window; @synthesize tabBarController; – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { LoginViewController_Pad *lvc = [[LoginViewController_Pad alloc] initWithNibName:@"LoginViewController_Pad" bundle:nil]; lvc.delegate = self; [window addSubview:lvc.view]; //[lvc […]

在iPhone中将UIViewController显示为Popup

由于对这个常见问题没有完整的,明确的答案,我会在这里提出并回答。 通常我们需要提供一个UIViewController ,它不会覆盖整个屏幕,如下图所示。 苹果提供了几个类似的UIViewController ,比如UIAlertView ,Twitter或者Facebook共享视图控制器等等。 我们如何才能达到这个自定义控制器的效果?

iPhone风景常见问题和解答

这里有很多的困惑和一系列相应的问题,所以iPhone应用程序如何正确处理横向/纵向模式自动旋转。 当需要以横向模式启动时,实现这样的应用特别困难。 观察到的最常见的效果是混乱的布局和不再识别触摸的屏幕区域。 一个简单的search标签iphone和landscape问题揭示了这些问题,这些问题发生在某些情况下: 横向只有iPhone应用程序与多个笔尖 :应用程序在横向模式下启动,从第一个笔尖视图呈现良好,从不同的笔尖加载的所有视图无法正确显示。 在加载新控制器时,Iphone Landscape模式切换到Portraite模式:自我解释 iPhone:在横向,只有在第一个addSubview之后,UITableViewController不能正确旋转 :与上面相同的问题。 iPhone横向专用实用程序 – 模板应用程序 :布局错误,控制器似乎无法识别应该旋转的视图,但在横向模式下显示剪辑的纵向视图,导致屏幕的一半保持空白。 presentModalViewController在纵向后的纵向viewController :模态视图不正确呈现。 已经提出了一套不同的解决scheme,其中一些解决scheme包括通过CoreGraphics完全定制的animation,而另一些解决schemebuild立在从主笔尖加载的第一个视图控制器始终显示正确的观察上。 我花了大量的时间调查这个问题,最终find了一个解决scheme,不仅是一个部分的解决scheme,而且应该在所有这些情况下工作。 这是我打算与这个CW职位提供一些常见问题解答在UIViewControllers景观模式的问题。 请提供反馈,并通过纳入任何相关意见来帮助提高本文的质量。 如果你知道的话,随时编辑和发布其他/更好的答案。

在AppDelegate.m的屏幕上获取当前显示的UIViewController

屏幕上的当前UIViewController需要响应来自APN的推送通知,通过设置一些徽章视图。 但是我怎么能得到方法application:didReceiveRemoteNotification的UIViewController application:didReceiveRemoteNotification :的AppDelegate.m ? 我尝试使用self.window.rootViewController获取当前显示的UIViewController ,它可能是一个UINavigationViewController或其他types的视图控制器。 我发现UINavigationViewController的visibleViewController属性可以用来获取屏幕上的UIViewController 。 但是,如果不是UINavigationViewController我该怎么办? 任何帮助表示赞赏! 相关的代码如下。 AppDelegate.m … – (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { //I would like to find out which view controller is on the screen here. UIViewController *vc = [(UINavigationViewController *)self.window.rootViewController visibleViewController]; [vc performSelector:@selector(handleThePushNotification:) withObject:userInfo]; } … ViewControllerA.m – (void)handleThePushNotification:(NSDictionary *)userInfo{ //set some badge view here }

CAGradientLayer,不好调整,撕裂旋转

我试图让我的CAGradientLayers,我用来创build漂亮的渐变背景,很好地调整旋转和模态视图呈现,但他们不会玩球。 这里是我刚刚创build的video,显示我的问题:注意旋转的撕裂。 另外请注意,这个video是通过在OS X上拍摄iPhone模拟器创build的。我放慢了video中的animation以突出显示我的问题。 问题的video… 这里是我刚刚创build的Xcode项目(这是video中显示的应用程序的源代码),基本上如图所示,问题发生在旋转,特别是当视图模式地呈现时: Xcode项目,模式呈现与CAGradientLayer背景的意见… 为什么这是值得我明白,使用: [[self view] setBackgroundColor:[UIColor blackColor]]; 做一个合理的工作,让过渡更无缝,更不刺激,但是如果你看着video,而我目前处于横向模式,模态地呈现一个视图,你会明白为什么上面的代码不会帮助。 任何想法我可以做什么来解决这个问题? 约翰