{"id":1275,"date":"2016-02-22T12:29:03","date_gmt":"2016-02-22T03:29:03","guid":{"rendered":"https:\/\/blog.ymyzk.com\/?p=1275"},"modified":"2016-05-14T14:42:53","modified_gmt":"2016-05-14T05:42:53","slug":"tttattributedlabel-peek-and-pop","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2016\/02\/tttattributedlabel-peek-and-pop\/","title":{"rendered":"TTTAttributedLabel \u3067 Peek & Pop \u306b\u5bfe\u5fdc\u3059\u308b (2016\u5e745\u6708\u66f4\u65b0)"},"content":{"rendered":"

TTTAttributedLabel<\/a> \u306f UILabel \u306e\u4ee3\u308f\u308a\u306b\u5229\u7528\u3067\u304d\u308b, \u30ea\u30f3\u30af\u306e\u691c\u51fa\u306a\u3069\u306e\u6a5f\u80fd\u3092\u5099\u3048\u305f\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059. \u3053\u306e\u8a18\u4e8b\u3067\u306f TTTAttributedLabel \u3067\u8868\u793a\u3057\u3066\u3044\u308b\u30ea\u30f3\u30af\u3092 iPhone 6s \/ 6s Plus \u3067\u5229\u7528\u3067\u304d\u308b\u00a03D Touch<\/a> \u306e\u6a5f\u80fd\u306e\u4e00\u3064\u3067\u3042\u308b Peek & Pop \u306b\u5bfe\u5fdc\u3055\u305b\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059.<\/p>\n

<\/p>\n

\u76ee\u6a19<\/h2>\n

\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3042\u308b ViewController \u306e subview \u3068\u3057\u3066\u00a0TTTAttributedLabel \u3092\u6301\u3061, \u3053\u306e\u00a0TTTAttributedLabel \u306e\u4e2d\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u30ea\u30f3\u30af\u3092 Peek & Pop \u306b\u5bfe\u5fdc\u3055\u305b\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059.<\/p>\n

\u52d5\u4f5c\u306e\u30a4\u30e1\u30fc\u30b8 (Tweetbot 4 \u3088\u308a):<\/p>\n

\"Tweetbot<\/a><\/p>\n

(\u203bTweetbot 4 \u304c\u00a0TTTAttributedLabel \u3092\u5229\u7528\u3057\u3066\u3044\u308b\u304b\u3069\u3046\u304b\u306f\u5206\u304b\u308a\u307e\u305b\u3093)<\/p>\n

TTTAttributedLabel \u3092 subview \u3068\u3057\u3066\u914d\u7f6e\u3055\u305b\u308b\u65b9\u6cd5\u3084,\u00a0TTTAttributedLabel \u3067\u30ea\u30f3\u30af\u3092\u691c\u51fa\u3057\u3066\u8868\u793a\u3059\u308b\u65b9\u6cd5\u306a\u3069\u306f\u3053\u306e\u8a18\u4e8b\u306e\u5bfe\u8c61\u5916\u3067\u3059.<\/p>\n

TTTAttributedLabel<\/h2>\n

\u73fe\u5728\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3066\u3044\u308b1.13.4 \u306f Peek & Pop \u306b\u5bfe\u5fdc\u3059\u308b\u305f\u3081\u306b\u4fbf\u5229\u306a\u30e1\u30bd\u30c3\u30c9 linkAtPoint<\/code> \u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u305b\u3093.\u00a0c9d9219<\/a> \u3067\u5b9f\u88c5\u3055\u308c\u3066\u3044\u308b\u306e\u3067, \u3053\u308c\u4ee5\u964d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092 Git \u3067\u53d6\u5f97\u3057\u3066\u5229\u7528\u3057\u3066\u304f\u3060\u3055\u3044.
\n<\/del><\/p>\n

2016\/5\/14 \u66f4\u65b0: 2016\/5 \u306b\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u305f 2.0.0<\/a> \u3067 -[TTTAttributedLabel linkAtPoint:]<\/code> \u304c\u516c\u958b\u3055\u308c\u307e\u3057\u305f. 2.0.0 \u4ee5\u964d\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u7528\u3044\u308b\u3053\u3068\u3067, \u4ee5\u4e0b\u306e\u624b\u9806\u306b\u5f93\u3063\u3066 3D Touch \u5bfe\u5fdc\u3092\u884c\u3048\u307e\u3059.<\/p>\n

viewDidLoad<\/h2>\n

Peek & Pop \u306b\u5bfe\u5fdc\u3059\u308b\u306b\u306f registerForPreviewingWithDelegate:sourceView:<\/code> \u3092\u7528\u3044\u3066, Peek & Pop \u3092\u5229\u7528\u3059\u308b\u30d3\u30e5\u30fc\u3092\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059. \u3053\u3053\u3067\u306f UIViewController\u00a0\u306e\u00a0view<\/code> \u3092\u767b\u9332\u3057\u307e\u3059.<\/p>\n

override func viewDidLoad() {\r\n    \/\/ \u7701\u7565\r\n\r\n    if traitCollection.forceTouchCapability == .Available {\r\n        registerForPreviewingWithDelegate(self, sourceView: view)\r\n    }\r\n}<\/pre>\n

UIViewControllerPreviewingDelegate<\/h2>\n

Peek & Pop \u306b\u5bfe\u5fdc\u3059\u308b\u306b\u306f ViewController \u3092 UIViewControllerPreviewingDelegate<\/code> \u306b\u9069\u5408\u3055\u305b\u307e\u3059. \u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059.<\/p>\n

extension ViewController: UIViewControllerPreviewingDelegate {\r\n    func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {\r\n        let point = previewingContext.sourceView.convertPoint(location, toView: label)\r\n        guard label.containslinkAtPoint(point) else { return nil }\r\n        guard let link = label.linkAtPoint(point),\r\n            url = link.result.URL else { return nil }\r\n        \/\/ previewingContext.sourceRect \u3092\u3088\u3057\u306a\u306b\u8a2d\u5b9a\u3059\u308b\r\n        let safariViewController = SFSafariViewController(URL: url)\r\n        return safariViewController\r\n    }\r\n\r\n    func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) {\r\n       \u3000presentViewController(viewControllerToCommit, animated: true, completion: nil)\r\n    }\r\n}<\/pre>\n

2\u884c\u76ee\u306e previewingContext:viewControllerForLocation:<\/code> \u306f Peek \u3059\u308b\u969b\u306b\u547c\u3073\u51fa\u3055\u308c\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059. location<\/code> \u306e\u5834\u6240\u306b\u3042\u308b\u30d3\u30e5\u30fc\u304c Peek \u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u306e\u3067\u3042\u308c\u3070, Peek \u3059\u308b ViewController \u3092\u8fd4\u3057, Peek \u306b\u5bfe\u5fdc\u3057\u3066\u3044\u306a\u3044\u306e\u3067\u3042\u308c\u3070 nil<\/code> \u3092\u8fd4\u3057\u307e\u3059.\u00a0\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306b\u306f\u6b21\u306e\u3088\u3046\u306a\u51e6\u7406\u304c\u5b9f\u88c5\u3055\u308c\u3066\u3044\u307e\u3059 (label<\/code> \u3092 TTTAttributedLabel \u3068\u3057\u307e\u3059):<\/p>\n