我正在使用Swift和Parse.com 为iOS制作应用程序
我试图让用户从图像选择器中选择一张图片,然后将所选图像调整为200x200像素,然后再上传到我的后端.
Parse.com有一个名为"AnyPic"的Instagram复制应用程序的教程,该应用程序提供了用于调整图像大小的代码,但它是在Objective-C ....
// Resize the image to be square (what is shown in the preview)
UIImage *resizedImage = [anImage resizedImageWithContentMode:UIViewContentModeScaleAspectFit
bounds:CGSizeMake(560.0f, 560.0f)
interpolationQuality:kCGInterpolationHigh];
// Create a thumbnail and add a corner radius for use in table views
UIImage *thumbnailImage = [anImage thumbnailImage:86.0f
transparentBorder:0.0f
cornerRadius:10.0f
interpolationQuality:kCGInterpolationDefault];
Run Code Online (Sandbox Code Playgroud)
如何在Swift中创建所选图片的200x200px版本(然后上传)?
而且,thumbnailImage函数在做什么?
我以前一直在从Parse后端检索图像,使用以下代码行在UIImageView中的应用程序中显示:
let userPicture = PFUser.currentUser()["picture"] as PFFile
userPicture.getDataInBackgroundWithBlock { (imageData:NSData, error:NSError) -> Void in
if (error == nil) {
self.dpImage.image = UIImage(data:imageData)
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
"AnyObject?不能转换为'PFFile'; 你的意思是用'as!' 迫使低垂?
"有用的"Apple修复技巧提示"as!" 改变所以我添加!,但后来我得到错误:
"AnyObject?不能转换为'PFFile'
使用'getDataInBackgroundWithBlock'部分,我也得到错误:
无法使用类型'((NSData,NSError) - > Void)的参数列表调用'getDataInBackgroundWithBlock'
有人可以解释如何从Parse正确检索照片并使用Swift 1.2在UIImageView中显示它吗?
我有一个嵌入在导航控制器中的视图控制器.
在导航栏上,我在栏的中心有一个segmentedControl,然后在右边有一个编辑按钮.
当我点击"编辑"按钮时,会触发以下代码:
func editAction() {
if homeworkTasksVC?.editing == false {
// Set to editing
homeworkTasksVC?.setEditing(true, animated: true)
// Switch to "Done" button and 'Homework' title without segmented control
let navBar = self.navigationController?.navigationBar
let navItem = UINavigationItem(title: "Homework")
let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: #selector(TasksParentViewController.editAction))
navItem.rightBarButtonItem = doneButton
navBar!.setItems([navItem], animated: true)
} else {
// Stop editing
homeworkTasksVC?.setEditing(false, animated: true)
// Switch back to "Edit" button and segmented control
let navBar = self.navigationController?.navigationBar
let navItem = UINavigationItem(title: "Homework") …Run Code Online (Sandbox Code Playgroud) 在iOS中,我正在使用Swift构建应用程序.我有一个视图,其中设置了容器视图,链接嵌入视图.这是使用Storyboard设置的.
如何在Swift代码中的视图之间设置委托关系,以便我可以在另一个视图中发送消息/触发器功能?
任何帮助,将不胜感激!