Swift 2-如何将UIImage分割到另一个自定义类并显示它?
如何将图像传输到另一个视图控制器?例如,此代码通过使用照相机功能拍摄照片,用户确认图像并将其显示在图像视图中,或者可以从“多媒体资料”中进行选择,一旦选择了图像,我如何将其转换为另一个自定义类 以下是ViewController.swift中的代码Swift 2-如何将UIImage分割到另一个自定义类并显示它?,swift,uiimageview,segue,Swift,Uiimageview,Segue,如何将图像传输到另一个视图控制器?例如,此代码通过使用照相机功能拍摄照片,用户确认图像并将其显示在图像视图中,或者可以从“多媒体资料”中进行选择,一旦选择了图像,我如何将其转换为另一个自定义类 以下是ViewController.swift中的代码 @IBAction func btnImagePicker1Clicked(sender: AnyObject) { let alert:UIAlertController=UIAlertController(title:
@IBAction func btnImagePicker1Clicked(sender: AnyObject)
{
let alert:UIAlertController=UIAlertController(title: "Choose Image", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let cameraAction = UIAlertAction(title: "Camera", style: UIAlertActionStyle.Default)
{
UIAlertAction in
self.openCamera()
}
let gallaryAction = UIAlertAction(title: "Gallery", style: UIAlertActionStyle.Default)
{
UIAlertAction in
self.openGallary()
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel)
{
UIAlertAction in
}
// Add the actions
SKIP2.hidden = true
BUTTON2.hidden = false
picker?.delegate = self
alert.addAction(cameraAction)
alert.addAction(gallaryAction)
alert.addAction(cancelAction)
// Present the controller
if UIDevice.currentDevice().userInterfaceIdiom == .Phone
{
self.presentViewController(alert, animated: true, completion: nil)
}
else
{
popover=UIPopoverController(contentViewController: alert)
popover!.presentPopoverFromRect(btnClickMe.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
}
func openCamera1()
{
if(UIImagePickerController .isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
{
picker!.sourceType = UIImagePickerControllerSourceType.Camera
self .presentViewController(picker!, animated: true, completion: nil)
}
else
{
openGallary1()
}
}
func openGallary1()
{
picker!.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
if UIDevice.currentDevice().userInterfaceIdiom == .Phone
{
self.presentViewController(picker!, animated: true, completion: nil)
}
else
{
popover=UIPopoverController(contentViewController: picker!)
popover!.presentPopoverFromRect(btnClickMe.frame, inView: self.view, permittedArrowDirections: UIPopoverArrowDirection.Any, animated: true)
}
}
func imagePickerController1(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
picker .dismissViewControllerAnimated(true, completion: nil)
imageView.image=info[UIImagePickerControllerOriginalImage] as? UIImage
}
func imagePickerControllerDidCancel1(picker: UIImagePickerController)
{
print("picker cancel.")
}
}
如果你有一个图库,你可以通过集合视图->didSelectItem()来解决这个问题,当你只想点击一个图像时,你可以在这个图像上放置一个没有文本的按钮,并从button@LucaArchidiacono你能告诉我这是怎么写的吗?我好像不明白干杯的人。