import UIKitclass SignUpVIEwController: UIVIEwController,UITextFIEldDelegate,UIPickerVIEwDataSource,UIPickerVIEwDelegate { @IBOutlet weak var profilePic: UIImageVIEw! overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // Do any additional setup after loading the vIEw. // PROfile PICTURE let tapGesture = UITapGestureRecognizer(target: self,action: "imageTapped:") profilePic.addGestureRecognizer(tapGesture) profilePic.userInteractionEnabled = true } func imageTapped(gesture:UIGestureRecognizer) { if let profile1Pic = gesture.vIEw as? UIImageVIEw { print("Image Tapped") } }解决方法 请尝试以下代码:
import UIKitclass SignUpVIEwController: UIVIEwController,UIImagePickerControllerDelegate {@IBOutlet weak var profilePic: UIImageVIEw!overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let tapGesture = UITapGestureRecognizer(target: self,action: "imageTapped:") profilePic.addGestureRecognizer(tapGesture) profilePic.userInteractionEnabled = true}func imageTapped(gesture:UIGestureRecognizer) { if let profile1Pic = gesture.vIEw as? UIImageVIEw { print("Image Tapped") showActionSheet() }}func camera(){ var myPickerController = UIImagePickerController() myPickerController.delegate = self; myPickerController.sourceType = UIImagePickerControllerSourceType.Camera self.presentVIEwController(myPickerController,animated: true,completion: nil)}func photolibrary(){ var myPickerController = UIImagePickerController() myPickerController.delegate = self; myPickerController.sourceType = UIImagePickerControllerSourceType.Photolibrary self.presentVIEwController(myPickerController,completion: nil)}func showActionSheet() { let actionSheet = UIAlertController(Title: nil,message: nil,preferredStyle: UIAlertControllerStyle.ActionSheet) actionSheet.addAction(UIAlertAction(Title: "Camera",style: UIAlertActionStyle.Default,handler: { (alert:UIAlertAction!) -> VoID in self.camera() })) actionSheet.addAction(UIAlertAction(Title: "gallery",handler: { (alert:UIAlertAction!) -> VoID in self.photolibrary() })) actionSheet.addAction(UIAlertAction(Title: "Cancel",style: UIAlertActionStyle.Cancel,handler: nil)) self.presentVIEwController(actionSheet,completion: nil)}func imagePickerController(picker: UIImagePickerController,dIDFinishPickingMediawithInfo info: [NSObject : AnyObject]) { profilePic.image = info[UIImagePickerControllerOriginalimage] as? UIImage self.dismissVIEwControllerAnimated(true,completion: nil)}}
它在我身边工作..希望会为你做一些!
总结以上是内存溢出为你收集整理的xcode – 以ActionSheet样式访问图片库全部内容,希望文章能够帮你解决xcode – 以ActionSheet样式访问图片库所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)