{"id":1998,"date":"2011-05-25T10:44:23","date_gmt":"2011-05-25T01:44:23","guid":{"rendered":"http:\/\/blog.bitmeister.jp\/?p=1998"},"modified":"2011-05-25T11:04:06","modified_gmt":"2011-05-25T02:04:06","slug":"setwantslayeryes%e3%81%ae%e5%be%8c%e3%83%ac%e3%82%a4%e3%83%a4%e3%83%bc%e3%81%aeframe%e3%81%8c%e5%a4%89%e3%82%8f%e3%82%8b","status":"publish","type":"post","link":"https:\/\/blog.bitmeister.jp\/?p=1998","title":{"rendered":"setWantsLayer:YES\u306e\u5f8c\u30ec\u30a4\u30e4\u30fc\u306eframe\u304c\u5909\u308f\u308b"},"content":{"rendered":"<p>Mac OS X \u306eCore Animation\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u305f\u3068\u304d\u306b\u3064\u307e\u305a\u3044\u305f\u3068\u3053\u308d\u3092\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>CIFilter\u3092\u4f7f\u3063\u3066\u753b\u50cf\u306e\u4e00\u90e8\u5206\u306b\u30d5\u30a3\u30eb\u30bf\u3092\u304b\u3051\u308b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u30d5\u30a3\u30eb\u30bf\u3092\u304b\u3051\u308b\u4f4d\u7f6e\u304c\u305a\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002<br \/>\n<!--more--><br \/>\n\u6b21\u306e\u69d8\u306bawakeFromNib\u306e\u4e2d\u3067CALayer\u306e\u30b3\u30f3\u30c6\u30f3\u30c4\u3092\u6307\u5b9a\u3057\u3001\u30d3\u30e5\u30fc\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre name=\"code\" class=\"c\">\r\n- (void)awakeFromNib {\r\n\r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u3092\u4f5c\u6210\u3059\u308b\r\n    CALayer* layer;\r\n    layer = [CALayer layer];\r\n\r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u306b\u753b\u50cf\u3092\u30bb\u30c3\u30c8\u3059\u308b\r\n    NSURL *imageUrl = [NSURL fileURLWithPath:\r\n      [[NSBundle mainBundle]pathForResource:@\"map\" ofType:@\"png\"]];\r\n    NSData *imageData =\r\n      [NSData dataWithContentsOfURL:imageUrl];\r\n    NSBitmapImageRep *imageRep =\r\n      [NSBitmapImageRep imageRepWithData:imageData];\r\n    layer.frame =\r\n      CGRectMake(0, 0, [imageRep pixelsWide], [imageRep pixelsHigh]);\r\n    layer.contents = (id)[imageRep CGImage];\r\n    layer.contentsGravity = kCAGravityCenter;\r\n\r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u3092\u30d3\u30e5\u30fc\u306b\u8a2d\u5b9a\u3059\u308b\r\n    [imageView setLayer:layer];\r\n    [imageView setWantsLayer:YES];\r\n\r\n}\r\n<\/pre>\n<p>\u753b\u9762\u306f\u3053\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u3059\u3002<br \/>\n<a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/4b85e2bb84b0cf87f1ba99cf11d9f33b.png\" title=\"\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/4b85e2bb84b0cf87f1ba99cf11d9f33b-269x300.png\" alt=\"\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u524d\u306e\u753b\u9762\" title=\"map1\" width=\"269\" height=\"300\" class=\"alignnone size-medium wp-image-2006\" srcset=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/4b85e2bb84b0cf87f1ba99cf11d9f33b-269x300.png 269w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/4b85e2bb84b0cf87f1ba99cf11d9f33b.png 520w\" sizes=\"auto, (max-width: 269px) 100vw, 269px\" \/><\/a><\/p>\n<p>\u753b\u9762\u306e&#8221;done&#8221;\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3068\u753b\u50cf\u306e\u5439\u304d\u51fa\u3057\u90e8\u5206\u306b\u30d5\u30a3\u30eb\u30bf\u304c\u304b\u304b\u308b\u306f\u305a\u306a\u306e\u3067\u3059\u304c\u30fb\u30fb\u30fb\u30fb\u3002<br \/>\n<a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2500f061760623d3f906449c38de60dc.png\" title=\"\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2500f061760623d3f906449c38de60dc-269x300.png\" alt=\"\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u5f8c\u306e\u753b\u50cf\uff08\u5931\u6557\uff09\" title=\"map2\" width=\"269\" height=\"300\" class=\"alignnone size-medium wp-image-2011\" srcset=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2500f061760623d3f906449c38de60dc-269x300.png 269w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2500f061760623d3f906449c38de60dc.png 520w\" sizes=\"auto, (max-width: 269px) 100vw, 269px\" \/><\/a><\/p>\n<p>\u6b8b\u5ff5\u306a\u611f\u3058\u306b\u30fb\u30fb\u30fb\u3002<\/p>\n<p>awakeFromNib\u3067CALayer\u306eframe.size.width\u3068frame.size.height\u306b\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u6307\u5b9a\u3057\u305f\u753b\u50cf\u306e\u6a2a\u3068\u7e26\u306e\u30d4\u30af\u30bb\u30eb\u6570(353,278)\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u3057\u304b\u3057\u3001\u8abf\u3079\u3066\u307f\u308b\u3068<\/p>\n<pre>[imageView setWantsLayer:YES];<\/pre>\n<p>\u306e\u5f8c\u3001frame.size.width\u3068frame.size.height\u306e\u5024\u304c\u30d3\u30e5\u30fc\u306eframe\u306e\u5024(400,400)\u306b\u5909\u308f\u3063\u3066\u3044\u308b\u306e\u3067\u3059\u3002\u3053\u308c\u304c\u539f\u56e0\u3067\u3057\u305f\u3002<br \/>\nCIFilter\u3067\u306f\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u6307\u5b9a\u3057\u305f\u753b\u50cf\u306e\u5927\u304d\u3055\u3092\u5143\u306b\u30d5\u30a3\u30eb\u30bf\u3092\u304b\u3051\u308b\u4f4d\u7f6e\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002\u3068\u3053\u308d\u304c\u3001\u30ec\u30a4\u30e4\u30fc\u306e\u5927\u304d\u3055\u304c\u753b\u50cf\u306e\u5927\u304d\u3055\u3068\u7570\u306a\u3063\u3066\u3044\u305f\u70ba\u3001\u30d5\u30a3\u30eb\u30bf\u3092\u5b9f\u884c\u3059\u308b\u4f4d\u7f6e\u304c\u305a\u308c\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u3059\u3002<\/p>\n<p>\u6b21\u306e\u69d8\u306b\u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u306b\u753b\u50cf\u3092\u30bb\u30c3\u30c8\u3057\u3066\u30d5\u30a3\u30eb\u30bf\u3092\u304b\u3051\u308b\u3068\u3001\u610f\u56f3\u3057\u305f\u4f4d\u7f6e\u3067\u30d5\u30a3\u30eb\u30bf\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<pre name=\"code\" class=\"c\">\r\n- (void)awakeFromNib {\r\n    \r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u3092\u4f5c\u6210\u3059\u308b\r\n    CALayer* layer;\r\n    layer = [CALayer layer];\r\n    \/\/ \u30ec\u30a4\u30a2\u30a6\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u306e\u8a2d\u5b9a\r\n    layer.layoutManager = [CAConstraintLayoutManager layoutManager];\r\n\r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u3092\u30d3\u30e5\u30fc\u306b\u8a2d\u5b9a\u3059\u308b\r\n    [imageView setLayer:layer];\r\n    [imageView setWantsLayer:YES];\r\n    \r\n    \/\/ \u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u3092\u4f5c\u6210\u3059\u308b\r\n    CALayer *imageLayer = [CALayer layer];\r\n\r\n    \/\/ \u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u306b\u753b\u50cf\u3092\u30bb\u30c3\u30c8\u3059\u308b\r\n    NSURL *imageUrl = [NSURL fileURLWithPath:\r\n      [[NSBundle mainBundle]pathForResource:@\"map\" ofType:@\"png\"]];\r\n    NSData *imageData =\r\n      [NSData dataWithContentsOfURL:imageUrl];\r\n    NSBitmapImageRep *imageRep =\r\n      [NSBitmapImageRep imageRepWithData:imageData];\r\n    imageLayer.frame =\r\n      CGRectMake(0, 0, [imageRep pixelsWide], [imageRep pixelsHigh]);\r\n    imageLayer.contents = (id)[imageRep CGImage];\r\n    imageLayer.contentsGravity = kCAGravityCenter;\r\n    \r\n    \/\/ \u30b9\u30fc\u30d1\u30fc\u30ec\u30a4\u30e4\u30fc\u306e\u4e2d\u5fc3\u306b\u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u3092\u8868\u793a\u3059\u308b\r\n    [imageLayer addConstraint:\r\n      [CAConstraint constraintWithAttribute:kCAConstraintMidY\r\n                                 relativeTo:@\"superlayer\"\r\n                                  attribute:kCAConstraintMidY]];\r\n\r\n    [imageLayer addConstraint:\r\n      [CAConstraint constraintWithAttribute:kCAConstraintMidX\r\n                                 relativeTo:@\"superlayer\"\r\n                                  attribute:kCAConstraintMidX]];\r\n    \r\n    \/\/ \u30ec\u30a4\u30e4\u30fc\u306b\u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u3092\u8ffd\u52a0\u3059\u308b\r\n    [layer addSublayer:imageLayer];\r\n\r\n}\r\n<\/pre>\n<p><a href=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2cf654ede85a8329bafbe371d7117888.png\" title=\"\" data-rel=\"lightbox-image-2\" data-rl_title=\"\" data-rl_caption=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2cf654ede85a8329bafbe371d7117888-269x300.png\" alt=\"\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u5b9f\u884c\u5f8c\u306e\u753b\u50cf\uff08\u6210\u529f\uff09\" title=\"map3\" width=\"269\" height=\"300\" class=\"alignnone size-medium wp-image-2026\" srcset=\"https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2cf654ede85a8329bafbe371d7117888-269x300.png 269w, https:\/\/blog.bitmeister.jp\/wp-content\/uploads\/2011\/05\/2cf654ede85a8329bafbe371d7117888.png 520w\" sizes=\"auto, (max-width: 269px) 100vw, 269px\" \/><\/a><\/p>\n<p>\u30ec\u30a4\u30a2\u30a6\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3092\u4f7f\u7528\u3057\u3066\u3001\u30b5\u30d6\u30ec\u30a4\u30e4\u30fc\u306e\u4f4d\u7f6e\u3092\u30b9\u30fc\u30d1\u30fc\u30ec\u30a4\u30e4\u30fc\u306e\u4f4d\u7f6e\u3092\u57fa\u6e96\u306b\u6c7a\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002Core Animation\u3084\u30ec\u30a4\u30e4\u306b\u3064\u3044\u3066\u306f<a href=\"http:\/\/developer.apple.com\/jp\/documentation\/Cocoa\/Conceptual\/CoreAnimation_guide\/Introduction\/Introduction.html\">Core Animation\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30ac\u30a4\u30c9<\/a>\u304c\u53c2\u8003\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u30ec\u30a4\u30a2\u30a6\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u306b\u3064\u3044\u3066\u306f\u3001<a href=\"http:\/\/developer.apple.com\/jp\/documentation\/Cocoa\/Conceptual\/CoreAnimation_guide\/Introduction\/Introduction.html\">Core Animation\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30ac\u30a4\u30c9<\/a>\u306e<a href=\"http:\/\/developer.apple.com\/jp\/documentation\/Cocoa\/Conceptual\/CoreAnimation_guide\/Articles\/Layout.html#\/\/apple_ref\/doc\/uid\/TP40006084\">Core Animation\u30ec\u30a4\u30e4\u306e\u914d\u7f6e<\/a>\u3092\u53c2\u8003\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mac OS X \u306eCore Animation\u3092\u4f7f\u3063\u305f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3057\u305f\u3068\u304d\u306b\u3064\u307e\u305a\u3044\u305f\u3068\u3053\u308d\u3092\u30e1\u30e2\u3057\u3066\u304a\u304d\u307e\u3059\u3002 CIFilter\u3092\u4f7f\u3063\u3066\u753b\u50cf\u306e\u4e00\u90e8\u5206\u306b\u30d5\u30a3\u30eb\u30bf\u3092\u304b\u3051\u308b\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u5b9f\u884c\u3057\u305f\u3044\u306e\u3067\u3059\u304c\u3001\u30d5\u30a3 [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[106,105,40],"class_list":["post-1998","post","type-post","status-publish","format-standard","hentry","category-tech","tag-cocoa","tag-mac-os-x","tag-40"],"_links":{"self":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1998","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1998"}],"version-history":[{"count":44,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1998\/revisions"}],"predecessor-version":[{"id":2044,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=\/wp\/v2\/posts\/1998\/revisions\/2044"}],"wp:attachment":[{"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1998"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1998"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bitmeister.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1998"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}