小编Kir*_*rby的帖子

如何删除以前的ViewController

我是一名学生,对编程很陌生.我想在业余时间学习Objective-C/Swift.我使用带有多个菜单/场景的swift的spriteKit制作了一个游戏.

我正试图从一个视图控制器转换到另一个视图控制器.为此,我使用了以下代码:

@IBAction func PlayButtonPressed(sender: AnyObject) {
    let playStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let vc : UIViewController = playStoryboard.instantiateViewControllerWithIdentifier("playGame") as UIViewController
    self.presentViewController(vc, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

这适用于转换到新的VC场景,但是,我相信以前的VC仍然在堆栈中并占用内存,从而减慢了我的程序.

我已阅读其他一些帖子,您可以使用导航控制器删除VC.但是,我没有导航控制器; 只查看控制器.我已经看过一些关于removeFromParentViewController()和的 东西view.removeFromSuperview(),但我真的不知道如何实现它.除此之外,我没有找到我正在寻找的答案.

所以我要问的问题是如何从堆栈中删除以前的VC?任何帮助将是一个赞赏!(希望帮助很快,但Objective-C也有帮助)提前谢谢!

备注供参考:我相信Objective-C我的代码看起来像这样:

-(IBAction) PlayButtonPressed: (id) sender {
    UIStoryboard *playStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [playStoryboard instantiateViewControllerWithIdentifier:@"playGame"];
    [self presentViewController:vc animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c uiviewcontroller ios swift

13
推荐指数
2
解决办法
1万
查看次数

截图在Iphone in swift只有一个白色背景

一些背景:我只是试图用一个简单的程序使用xcode 6 beta 7在swift中按下按钮后截图iphone.它在SpiteKit和游戏场景中完成.背景是随机png图像和"hello world"默认示例文本.我使用以下代码以编程方式在gamescene didMoveToView函数中放置一个可按下按钮(默认的太空船图像是按钮):

button.setScale(0.2)
screen.frame = CGRect(origin: CGPointMake(self.size.width/4, self.size.height/1.5), size: button.size)
screen.setImage(playAgainButton, forState: UIControlState.Normal)
screen.addTarget(self, action: "action:", forControlEvents: UIControlEvents.TouchUpInside)
self.view!.addSubview(screen)
Run Code Online (Sandbox Code Playgroud)

这会在屏幕上设置我的可按下按钮,在该按钮上链接到一个功能,使用下面的代码截取屏幕截图:

func action(sender:UIButton!){
    UIGraphicsBeginImageContext(self.view!.bounds.size)
    self.view!.layer.renderInContext(UIGraphicsGetCurrentContext())
    let screenshot = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil)
}
Run Code Online (Sandbox Code Playgroud)

所以这个代码采取截图,但是当我看着照片,只压按钮可以显示与图像的其余部分是白色的.图像如下所示:

截图

下面,我认为屏幕截图应该是这样的,因为这是屏幕在模拟器中的样子(我只是使用了一些随机图像/文本作为背景):

在此输入图像描述

有人可以向我解释为什么屏幕截图程序还没有拍摄背景图片以及如何修复它?

我已经在线查看了,我还没有看到任何问题可以解决我的问题.在线我看到了一些类似的问题并尝试了他们的修复:我导入了quartzCore,coreGraphics和coreImages,但没有修复.此外,我尝试使用ViewController并在那里设置一个带有IBaction的UI按钮进行屏幕截图,但仍然获得相同的白色背景图像.我尝试了不同的背景图像,结果相同.

我对编程很新,所以,任何帮助将不胜感激!先感谢您!

screenshot image ios sprite-kit swift

6
推荐指数
1
解决办法
2781
查看次数

是否可以在独立脚本中使用 Vapor 3 Postgres Fluent?

我正在试验一个独立的脚本,该脚本将使用 Vapor 和 Fluent 查询 Postgres 数据库。在普通的 Vapor API 应用程序中,这只需通过以下方式完成:

router.get("products") { request in
    return Product.query(on: request).all()
}
Run Code Online (Sandbox Code Playgroud)

然而,在一个独立的脚本中,由于没有“请求”,我陷入了用什么来替换“请求”的问题DatabaseConnectable上。这是我陷入困境的地方:

import Fluent
import FluentPostgreSQL

let databaseConfig = PostgreSQLDatabaseConfig(hostname: "localhost",
                                              username: "test",
                                              database: "test",
                                              password: nil)

let database = PostgreSQLDatabase(config: databaseConfig)

let foo = Product.query(on: <??WhatDoIPutHere??>)
Run Code Online (Sandbox Code Playgroud)

我尝试创建一个符合 的对象DatabaseConnectable,但无法弄清楚如何正确地使该对象符合 。

swift vapor

5
推荐指数
1
解决办法
350
查看次数