【发布时间】:2018-12-26 10:23:59
【问题描述】:
i 创建了一个应用程序菜单,用户可以在其中单击照片,图片显示在 alertView 中,我添加了 2 个操作 -> 一个操作是取消,另一个操作是编辑图像,应该打开图库以选择其他图像。但是,当我单击编辑按钮(已添加代码)时,它什么也不做,并且与关闭警报视图相同。 ALERTVIEW 的代码是
@objc func taxImageTApped(_snder:UITapGestureRecognizer) {
print("TaxImage")
let alertView = UIAlertController(title: "Edit Tax Image", message: "", preferredStyle: UIAlertController.Style.alert)
let image = #imageLiteral(resourceName: "backimg@3x.png")
let uiImageAlertAction = UIAlertAction(title: "", style: .default, handler: nil)
let scaleSze = CGSize(width: 245, height: 245/image.size.width*image.size.height)
let reSizedImage = image//.resize(newSize: scaleSze)
uiImageAlertAction.setValue(reSizedImage.withRenderingMode(.alwaysOriginal), forKey: "image")
alertView.addAction(uiImageAlertAction)
alertView.addAction(UIAlertAction(title: "Cancel", style: UIAlertAction.Style.default, handler: nil))
alertView.addAction(UIAlertAction(title: "Edit", style: .default) {action in
let newImage = UIImagePickerController()
newImage.delegate = self
newImage.sourceType = UIImagePickerController.SourceType.photoLibrary
newImage.allowsEditing = false
})
self.present(alertView, animated: true, completion: nil)
}
/////////////////////below is details for tap gesture i have applied on //the label
taxImageView.translatesAutoresizingMaskIntoConstraints = false
taxImageView.textColor = tableTextColor
taxImageView.text = "View Image"
taxImageView.textAlignment = .left
taxImageView.attributedText = NSAttributedString(string: "View Image", attributes:
[.underlineStyle: NSUnderlineStyle.single.rawValue])
editInfoView.addSubview(taxImageView)
taxImageView.leftAnchor.constraint(equalTo: editInfoView.leftAnchor, constant: 260).isActive = true
taxImageView.topAnchor.constraint(equalTo: editInfoView.topAnchor, constant: 740).isActive = true
taxImageView.widthAnchor.constraint(equalToConstant: 300).isActive = true
taxImageView.heightAnchor.constraint(equalToConstant: 20).isActive = true
taxImageView.isUserInteractionEnabled = true
let taxImageGesture = UITapGestureRecognizer.init(target: self, action: #selector(taxImageTApped))
taxImageGesture.numberOfTapsRequired = 1
taxImageGesture.isEnabled = true
taxImageGesture.cancelsTouchesInView = false
taxImageView.gestureRecognizerShouldBegin(taxImageGesture)
taxImageView.addGestureRecognizer(taxImageGesture)
【问题讨论】:
标签: ios swift uialertview uitapgesturerecognizer photo-gallery