{"id":345,"date":"2013-02-20T14:44:41","date_gmt":"2013-02-20T05:44:41","guid":{"rendered":"http:\/\/androiphone.uvs.jp\/?p=345"},"modified":"2015-11-09T14:04:45","modified_gmt":"2015-11-09T05:04:45","slug":"ioscocos2duirotationgesturerecognizer%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%ad%e3%83%bc%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%82%b8%e3%82%a7%e3%82%b9%e3%83%81%e3%83%a3%e3%82%92","status":"publish","type":"post","link":"https:\/\/androiphone.uvs.jp\/?p=345","title":{"rendered":"[iOS][cocos2d]UIRotationGestureRecognizer\u3092\u4f7f\u3063\u3066\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u30b8\u30a7\u30b9\u30c1\u30e3\u3092\u691c\u51fa\u3059\u308b"},"content":{"rendered":"<p>cocos2d\u3067\u30b9\u30d7\u30e9\u30a4\u30c8\u3092\u30bf\u30c3\u30d7\u3057\u3066D&amp;D\u3067\u79fb\u52d5\u3059\u308b\u306a\u3069\u306fCCStandardTouchDelegate\u3092\u5b9f\u88c5\u3057\u3066\u3001<\/p>\n<pre>[objc]\r\n- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event\r\n- (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event\r\n- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event\r\n[\/objc]<\/pre>\n<p>\u3067\u8a18\u8ff0\u3059\u308c\u306f\u3001\u96e3\u306a\u304f\u3067\u304d\u308b\u3002\u30b9\u30d7\u30e9\u30a4\u30c8\u306e\u79fb\u52d5\u5236\u9650(\u5ea7\u6a19\u6f14\u7b97)\u306f\u3053\u3053\u306b\u8a18\u8ff0\u3059\u308c\u3070\u3044\u3044\u3002 \u30b8\u30a7\u30b9\u30c1\u30e3\u30fc(\u30b9\u30ef\u30a4\u30d7\u30fb\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3)\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u3082\u3001\u30b8\u30a7\u30b9\u30c1\u30e3\u691c\u51fa\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3059\u308b\u65b9\u6cd5 \u304c\u3042\u308a\u3001\u307e\u305f\u6709\u5fd7\u306e\u65b9\u3005\u3067\u30af\u30e9\u30b9\u5316\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u5b9f\u969b\u3001\u30b8\u30a7\u30b9\u30c1\u30e3\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u306e\u306f\u3001\u3068\u3063\u3066\u3082\u3081\u3093\u3069\u304f\u3055\u3044\u3002\u3068\u3044\u3046\u308f\u3051\u3067<\/p>\n<p><a href=\"http:\/\/www.supersuraccoon-cocos2d.com\/ja\/2012\/11\/14\/introduction-to-some-great-ios-gesture-recognition-libraries-cocos2d\/\">http:\/\/www.supersuraccoon-cocos2d.com\/ja\/2012\/11\/14\/introduction-to-some-great-ios-gesture-recognition-libraries-cocos2d\/<\/a><\/p>\n<p>\u4e0a\u306e\u30b5\u30a4\u30c8\u3092\u307f\u3066\u307f\u308b\u3068\u3001CCStandardTouchDelegate\u3068UIGestureRecognizer\u3067\u306e\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u5b9f\u88c5\u304c\u3042\u308a\u3001 \u4eca\u56de\u306f\u3001\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u691c\u51fa\u3059\u308b\u305f\u3081\u306bUIGestureRecognizer\u306e\u30b5\u30d6\u30af\u30e9\u30b9\u306eUIRotationGestureRecognizer\u3092\u4f7f\u3063\u305f\u691c\u51fa\u3092\u3057\u3066\u307f\u305f\u3002 \u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u691c\u51fa\u81ea\u4f53\u306f\u52dd\u624b\u306b\u3084\u3063\u3066\u304f\u308c\u308b\u3002\u30a4\u30cb\u30b7\u30e3\u30e9\u30a4\u30b6\u304b\u306a\u3093\u304b\u3067\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u5b9f\u88c5\u3057\u3066\u3001\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u6642\u306bselector\u304c\u547c\u3070\u308c\u308b\u306e\u3067\u3001\u305d\u3053\u3067\u51e6\u7406\u3092\u884c\u3046\u3002<\/p>\n<pre>[objc]\r\n        UIRotationGestureRecognizer* rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationGesture:)];\r\n        [[[CCDirector sharedDirector] view] addGestureRecognizer:rotationGesture];\r\n[\/objc]<\/pre>\n<pre>[objc]\r\n- (void) handleRotationGesture:(UIRotationGestureRecognizer*) sender {\r\n    \r\n    UIRotationGestureRecognizer* rotation = (UIRotationGestureRecognizer*) sender;\r\n    float dgree = rotation.rotation * 180.0f \/ M_PI;\r\n    CGSize screenSize = [[CCDirector sharedDirector] winSize];\r\n    \r\n    if(rotation.state==UIGestureRecognizerStateBegan){\r\n        \/\/\u56de\u8ee2\u5bfe\u8c61\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u306e\u7279\u5b9a\r\n        \/\/moji_rotate = nil;\r\n        if([rotation numberOfTouches]==2){ \/\/\u4e8c\u672c\u6307\u3067\u30bf\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u3068\u304d\r\n            CGPoint fin1_pos = [rotation locationOfTouch:0 inView:[[CCDirector sharedDirector] view]];\r\n            CGPoint fin2_pos = [rotation locationOfTouch:1 inView:[[CCDirector sharedDirector] view]];\r\n            \/\/Y\u8ef8\u306e\u53cd\u8ee2\r\n            fin1_pos.y = screenSize.height - fin1_pos.y;\r\n            fin2_pos.y = screenSize.height - fin2_pos.y;\r\n            \r\n            int z = -1;\r\n            for(int i=0;i&amp;lt;[chars count];i++){\r\n                CharPanel *moji_buf = [chars objectAtIndex:i];\r\n                float h_value = moji_buf.boundingBox.size.height;\r\n                float w_value = moji_buf.boundingBox.size.width;\r\n                float dist = sqrtf(pow(h_value,2)+pow(w_value,2))\/2 + 0; \/\/\u30b9\u30d7\u30e9\u30a4\u30c8\u4e2d\u5fc3\u304b\u3089\u306e\u8a31\u5bb9\u8ddd\u96e2\u3092\u6c42\u3081\u308b\r\n                \r\n                float fin1_dist = [self getdistance:fin1_pos:moji_buf.position];\r\n                float fin2_dist = [self getdistance:fin2_pos:moji_buf.position];\r\n                \r\n                if((fin1_dist&amp;lt;dist)&amp;amp;&amp;amp;(fin2_dist&amp;lt;dist)){\r\n                    if(moji_buf.zOrder&amp;gt;z){  \/\/\u4e00\u756a\u4e0a\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u3092\u5bfe\u8c61\u306b\u3059\u308b\r\n                        z = moji_buf.zOrder;\r\n                        moji_rotate = [chars objectAtIndex:i];\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    \r\n    }else if(rotation.state==UIGestureRecognizerStateEnded){\r\n        \r\n        if(moji_rotate!=nil){\r\n            [moji_rotate setDgree:[moji_rotate getDgree] + dgree];\r\n            moji_rotate = nil;\r\n        }\r\n    \r\n    }else{\r\n        \r\n        if(moji_rotate!=nil){\r\n            moji_rotate.rotation = [moji_rotate getDgree] + dgree;\r\n        }\r\n    }\r\n}\r\n[\/objc]<\/pre>\n<p>\u3000\u5197\u9577\u306a\u30b3\u30fc\u30c9\u3067\u7533\u3057\u8a33\u306a\u3044\u3067\u3059\u304c\u3001(NSMutablearray*)chars\u306b\u306f\u30b9\u30d7\u30e9\u30a4\u30c8(CCSprite\u306e\u30b5\u30d6\u30af\u30e9\u30b9)\u304c\u914d\u5217\u3068\u3057\u3066\u5165\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3000\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u306e\u72b6\u614b\u306fUIRotationGestureRecognizer\u306estate\u3067\u691c\u51fa\u3057\u307e\u3059\u3002\u307e\u305a\u306fUIGestureRecognizerStateBegan\u306b\u3066\u958b\u59cb\u90e8\u304b\u3089\u3067\u3059 \u3000<\/p>\n<p>\u3053\u3053\u3067\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u306a\u3089\u30702\u672c\u306e\u6307\u304c\u5fc5\u9808\u3068\u306f\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u72b6\u614b\u3092\u8ffd\u3063\u3066\u307f\u308b\u3068numberOfTouches\u304c1\u3092\u8fd4\u3059\u3068\u304d\u3082\u591a\u3005\u3042\u308a\u307e\u3059\u3002 \u3053\u306e\u305f\u30812\u4ee5\u5916\u306f\u7121\u8996\u3057\u307e\u3059\u30022\u3064\u306e\u6307\u306e\u30bf\u30c3\u30c1\u5ea7\u6a19\u3092\u8a18\u9332\u3057\u307e\u3059\u3002\u3053\u306e\u3068\u304d\u3001CG\u3068UIVIew\u306e\u5ea7\u6a19\u306e\u9055\u3044\u304b\u3089\u53d6\u5f97\u5ea7\u6a19\u306eY\u8ef8\u304c\u53cd\u8ee2\u3059\u308b\u3053\u3068\u3092 \u5fd8\u308c\u306a\u3044\u3067\u304f\u3060\u3055\u3044\u3002\u3064\u307e\u308a\u306fCG\u5ea7\u6a19(cocos2d)\u306b\u5909\u63db\u3057\u307e\u3059\u3002 \u3000\u3053\u3053\u304b\u3089\u306e\u51e6\u7406\u306f\u76f4\u63a5\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u3068\u95a2\u4fc2\u306a\u3044\u3067\u3059\u304c\u3001\u3061\u306a\u307f\u306bchars\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u306f\u3001\u307b\u307c\u6b63\u65b9\u5f62\u524d\u63d0\u3068\u3057\u307e\u3059\u3002chars\u683c\u7d0d\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u306e\u5bfe\u89d2\u7dda\u306e 1\/2\u3092\u534a\u5f84\u3068\u3059\u308b\u5186\u306e\u4e2d\u306b2\u3064\u306e\u6307\u306e\u5ea7\u6a19\u304c\u542b\u307e\u308c\u3066\u3044\u308c\u3070\u5bfe\u8c61\u30b9\u30d7\u30e9\u30a4\u30c8\u3068\u5224\u65ad\u3057\u307e\u3059\u3002\u307e\u305f\u3001chars\u304b\u3089\u8907\u6570\u691c\u51fa\u3055\u308c\u308b\u3070\u3042\u3044\u306f\u3001\u91cd\u306a\u3063\u3066\u3044\u308b\u3068 \u5224\u65ad\u3057\u3001z\u5024\u3092\u53c2\u8003\u306b\u4e00\u756a\u4e0a\u306e\u30b9\u30d7\u30e9\u30a4\u30c8\u3092\u5bfe\u8c61\u30b9\u30d7\u30e9\u30a4\u30c8\u3068\u5224\u65ad\u3057\u307e\u3059\u3002\u5bfe\u8c61\u30b9\u30d7\u30e9\u30a4\u30c8\u306fmoji_rotaion\u306b\u5165\u308a\u307e\u3059\u3002 \u3000<\/p>\n<p>\u3042\u3068\u306f\u30b9\u30d7\u30e9\u30a4\u30c8\u306erotation\u306b\u3069\u306e\u304f\u3089\u3044\u56de\u8ee2\u3055\u305b\u305f\u304b\u3092UIRotationGestureRecognizer\u306erotation\u3088\u308a\u4ee3\u5165\u3059\u308c\u3070\u3088\u3044\u3067\u3059\u3002\u3061\u306a\u307f\u306b\u3001 \u30b9\u30d7\u30e9\u30a4\u30c8\u306erotation\u306f\u5ea6\u6570\u6cd5\u3067UIRotationGestureRecognizer\u306f\u5f27\u5ea6\u6cd5\u3067\u3059\u3002\u3053\u3053\u3067\u306f\u5ea6\u6570\u6cd5\u306b\u5909\u63db\u3057\u3066\u3044\u307e\u3059\u3002 \u3000<\/p>\n<p>\u4e0a\u306e\u30b3\u30fc\u30c9\u3067\u306f\u30b9\u30d7\u30e9\u30a4\u30c8\u81ea\u4f53\u304c\u3069\u308c\u3060\u3051\u56de\u8ee2\u3057\u3066\u3044\u308b\u304b\u3092\u4fdd\u6301\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u305f\u3081\u3001UIGestureRecognizerStateEnded\u3067\u3001CCSprite\u306e \u30b5\u30d6\u30af\u30e9\u30b9\u306b\u3066\u30e1\u30f3\u30d0\u5909\u6570rotation\u306b\u3066\u56de\u8ee2\u89d2\u5ea6\u3092\u4fdd\u6301\u3055\u305b\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30b8\u30a7\u30b9\u30c1\u30e3\u30fc\u304c\u7d42\u308f\u3063\u305f\u3068\u5224\u65ad\u3059\u308b\u305f\u3081moji_rotation\u306b\u306fnil\u3092\u5165\u308c\u307e\u3059\u3002 \u3000\u3042\u3068\u306fstate\u5224\u65ad\u306eeles\u3067\u5b9f\u969b\u3001\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u3066\u3044\u308b\u3068\u304d\u306b\u89d2\u5ea6\u3092\u4ee3\u5165\u3059\u308b\u3060\u3051\u3067\u3059\u3002<\/p>\n<p>\u3000rotation\u3060\u3089\u3051\u306e\u30b3\u30fc\u30c9\u3067\u3001\u305d\u30fc\u3068\u30fc\u308f\u304b\u308a\u306b\u304f\u3044\u3067\u3059\u3002\u3002\u5225\u306e\u540d\u524d\u306b\u3057\u308d\u3088!\u3068\u8a00\u308f\u308c\u305d\u3046\u3067\u3059\u304c\u30fb\u30fb\u30fb\u304c\u6642\u9593\u3082\u306a\u304f\u2026\u5fa1\u5bdf\u3057\u304f\u3060\u3055\u3044w<\/p>\n","protected":false},"excerpt":{"rendered":"<p>cocos2d\u3067\u30b9\u30d7\u30e9\u30a4\u30c8\u3092\u30bf\u30c3\u30d7\u3057\u3066D&amp;D\u3067\u79fb\u52d5\u3059\u308b\u306a\u3069\u306fCCStandardTouchDelegate\u3092\u5b9f\u88c5\u3057\u3066\u3001 [objc] &#8211; (void)ccTouchesBegan:(NSSet *)touches [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"","_original_post":"","footnotes":""},"categories":[7,8],"tags":[],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-ios","category--ios","ja"],"_links":{"self":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":17,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"predecessor-version":[{"id":924,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions\/924"}],"wp:attachment":[{"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/androiphone.uvs.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}