Created
April 12, 2015 14:48
-
-
Save matsuhisa/41ed0624a484edeca40c to your computer and use it in GitHub Desktop.
Swift で UIActivityViewController を利用してfacebookやTwitterにシェアをする ref: http://qiita.com/matsuhisa@github/items/7a599e0276cfabe1090e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ButtonShare.addTarget(self, action: "share_action:", forControlEvents: .TouchUpInside) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 長押し | |
var myLongPressGesture = UILongPressGestureRecognizer(target: self, action: "lognPress:") | |
// 長押し - 2.0秒 | |
myLongPressGesture.minimumPressDuration = 2.0 | |
// 長押し - 許容範囲15px | |
myLongPressGesture.allowableMovement = 150 | |
// 画像に長押しがあったときの対応 | |
SampleImage.userInteractionEnabled = true | |
SampleImage.addGestureRecognizer(myLongPressGesture) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Social | |
class DetailViewController: UIViewController { | |
@IBOutlet weak var detailDescriptionLabel: UILabel! | |
@IBOutlet weak var ButtonShare: UIButton! | |
@IBOutlet weak var SampleImage: UIImageView! | |
func configureView() { | |
if let detail: AnyObject = self.detailItem { | |
if let label = self.detailDescriptionLabel { | |
label.text = detail.description | |
} | |
} | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.configureView() | |
// 長押し | |
var myLongPressGesture = UILongPressGestureRecognizer(target: self, action: "lognPress:") | |
// 長押し - 2.0秒 | |
myLongPressGesture.minimumPressDuration = 2.0 | |
// 長押し - 許容範囲15px | |
myLongPressGesture.allowableMovement = 150 | |
// 画像に長押しがあったときの対応 | |
SampleImage.userInteractionEnabled = true | |
SampleImage.addGestureRecognizer(myLongPressGesture) | |
// share | |
ButtonShare.addTarget(self, action: "share_action:", forControlEvents: .TouchUpInside) | |
} | |
func lognPress(sender: UILongPressGestureRecognizer) { | |
println("lognPress") | |
share_action(self) | |
} | |
func share_action(sender: AnyObject) { | |
println("share_action") | |
let secondActivityItem = "iOSからのテストです #桜" | |
let firstActivityItem:UIImage = SampleImage.image! as UIImage | |
let activityViewController = UIActivityViewController( | |
activityItems: [firstActivityItem, secondActivityItem], | |
applicationActivities: nil) | |
activityViewController.completionWithItemsHandler = {(activityType, completed:Bool, returnedItems:Array!, error:NSError!) in | |
if (completed) { | |
// ここに完了後の処理を書く | |
println("完了!") | |
} | |
} | |
self.presentViewController(activityViewController, animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment