按钮中的序列事件
sequence events in a button
在我的正下方有 2 个按钮。放置按钮需要在 magicjohnson 按钮之前按下,否则会出现运行时错误。
@IBAction func magicJohnson(_ sender: Any) {
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
@IBAction func place(_ sender: Any) {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
}
我怎样才能获得代码来执行此操作/
@IBAction func magicJohnson(_ sender: Any) {
FIRST {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
}
second{
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}
}}
试试这个,将 placeBu
声明为 IBOutlet
@IBAction func magicJohnson(_ sender: Any) {
self.place(self.placeBu) // may be self.place(UIButton()) if you don't care of sender instead of the outlet
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
或者
@IBAction func magicJohnson(_ sender: Any) {
if let photo = self.imageV.image
{
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
}
}
或者在 Interface builder 中将 magicJohnson
按钮的启用设置为 false
@IBAction func place(_ sender: Any) {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
self.magicJohnson.isEnabled = true
}
在我的正下方有 2 个按钮。放置按钮需要在 magicjohnson 按钮之前按下,否则会出现运行时错误。
@IBAction func magicJohnson(_ sender: Any) {
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
@IBAction func place(_ sender: Any) {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
}
我怎样才能获得代码来执行此操作/
@IBAction func magicJohnson(_ sender: Any) {
FIRST {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
}
second{
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}
}}
试试这个,将 placeBu
声明为 IBOutlet
@IBAction func magicJohnson(_ sender: Any) {
self.place(self.placeBu) // may be self.place(UIButton()) if you don't care of sender instead of the outlet
let photo = self.imageV.image
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
或者
@IBAction func magicJohnson(_ sender: Any) {
if let photo = self.imageV.image
{
let data = UIImagePNGRepresentation(photo!)
if cdHandler.saveObject(pic: data!){
}}
}
}
或者在 Interface builder 中将 magicJohnson
按钮的启用设置为 false
@IBAction func place(_ sender: Any) {
let image = UIImage.imageWithView(view: theView)
let heart:UIImage = UIImage(named: "words")!
let left:UIImage = image
let newSize2 = CGSize(width: left.size.width, height: left.size.height)
UIGraphicsBeginImageContextWithOptions(newSize2, false, left.scale)
left.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
heart.draw(in: CGRect(x: 0,y: 0,width: newSize2.width,height: newSize2.height), blendMode:CGBlendMode.normal, alpha:1.0)
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
imageV.image = newImage
self.magicJohnson.isEnabled = true
}