Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone


iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer) สำหรับ Rotation Gesture เป็น Gesture บน iOS ในรูปแบบของการใช้ นิ้วตั้งแต่ 2 นิ้วขึ้นไป ทำการหมุ่ม (Rotate) รายการ View หรือ Object ต่าง ๆ บนหน้าจอ Application โดย Rotation Gesture จะใช้ Class ของ UIRotationGestureRecognizer ในการที่จะ Detect Gesture ที่เกิดขึ้น

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)


Rotation Gesture Recognizer (UIRotationGestureRecognizer) อาจจะไม่ค่อยได้พบเจอได้ง่ายนักใน Application ทั่ว ๆ ไป เพราะส่วนมากอาจจะได้ใช้กับ Application ที่เกี่ยวข้องกับ Graphic ซะมากกว่า แต่การใช้งานก็ไม่ได้ยากอะไรมากมาย

การหมุน Rotation Gesture บน iOS Simulator
สามารถใช้การกดปุ่ม Option บน Keyboard แล้วคลิกแล้วหมุ่นเมาส์บนหน้า Simulator


Rotation Gesture Recognizer (UIRotationGestureRecognizer)
01.- (void)viewDidLoad
02.{
03.    [super viewDidLoad];
04.    // Do any additional setup after loading the view, typically from a nib.
05.     
06.    // Rotation Gesture
07.    UIRotationGestureRecognizer *rotationGesture =[[UIRotationGestureRecognizer alloc]
08.                                                   initWithTarget: self
09.                                                   action: @selector(rotationGuestureHandle:)];
10.    [[self view] addGestureRecognizer:rotationGesture];
11.}
12. 
13.-(void) rotationGuestureHandle:(UIRotationGestureRecognizer *) sender {
14.     
15.    NSLog(@"Rotation Gesture Handling");
16.     
17.}


Example การใช้ Rotation Gesture (UIRotationGestureRecognizer) ในการหมุ่นรูปภาพ Image View (UIImageView)

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

เริ่มต้นด้วยการสร้าง Project บน Xcode แบบง่าย ๆ ด้วย Single View Application



iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

เลือกและไม่เลือกรายการดังรูป

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

ตอนนี้หน้าจอ View จะยังว่าง ๆ

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

ทำการ Add ไฟล์รูปภาพเข้ามาใน Project

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

ทำการลาก Object ที่มีชื่อว่า Image View (UIImageView) เข้าในหน้าจอ Design ของ View

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

เลือกรูปภาพเพื่อแสดงบน Image View

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

ใน Class ของ .h ให้เชื่อม IBOutlet ให้กับ Image View

Code ทั้งหมดของ .h และ .m ในภาษา Objective-C

ViewController.h
01.//
02.//  ViewController.h
03.//  rotationGesture
04.//
05.//  Created by Weerachai on 11/17/55 BE.
06.//  Copyright (c) 2555 Weerachai. All rights reserved.
07.//
08. 
09.#import <UIKit/UIKit.h>
10. 
11.@interface ViewController : UIViewController
12.{
13.    IBOutlet UIImageView *imgView;
14.}
15. 
16.@end


ViewController.m
01.//
02.//  ViewController.m
03.//  rotationGesture
04.//
05.//  Created by Weerachai on 11/17/55 BE.
06.//  Copyright (c) 2555 Weerachai. All rights reserved.
07.//
08. 
09.#import "ViewController.h"
10. 
11.@interface ViewController ()
12. 
13.@end
14. 
15.@implementation ViewController
16. 
17.- (void)viewDidLoad
18.{
19.    [super viewDidLoad];
20.    // Do any additional setup after loading the view, typically from a nib.
21.     
22.    // Rotation Gesture
23.    UIRotationGestureRecognizer *rotationGesture =[[UIRotationGestureRecognizer alloc]
24.                                                   initWithTarget: self
25.                                                   action: @selector(rotationGuestureHandle:)];
26.    [[self view] addGestureRecognizer:rotationGesture];
27.}
28. 
29.-(void) rotationGuestureHandle:(UIRotationGestureRecognizer *) sender {
30.     
31.    NSLog(@"Rotation Gesture Handling");
32.     
33.    UIRotationGestureRecognizer *rotation = (UIRotationGestureRecognizer *)sender;
34.     
35.    CGFloat angle = rotation.rotation;
36.    imgView.transform = CGAffineTransformRotate(imgView.transform, angle);
37.    rotation.rotation=0.0;
38.}
39. 
40.- (void)didReceiveMemoryWarning
41.{
42.    [super didReceiveMemoryWarning];
43.    // Dispose of any resources that can be recreated.
44.}
45. 
46.- (void)dealloc {
47.    [imgView release];
48.    [super dealloc];
49.}
50.@end




Screenshot

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

แสดงการปุ่ม Rotation Gesture ของรูปภาพ

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

แสดงการปุ่ม Rotation Gesture ของรูปภาพ

iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)

แสดงการปุ่ม Rotation Gesture ของรูปภาพ

   
Hate it
Don't like it
It's ok
Like it
Love it
Total Votes: 43Overall Rating: 3.8 / 5
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-11-20 10:02:53 / 2017-03-26 09:53:12
  Download : Download  iOS/iPhone Rotation Gesture Recognizer (UIRotationGestureRecognizer)
 Sponsored Links / Related

 
iOS/iPhone Swipe Gesture and Storyboard , View (Objective-C, iPhone, iPad)
Rating :

 
iOS/iPhone Gesture Recognizer (UIGestureRecognizer) - (Objective-C , iPhone)
Rating :

 
iOS/iPhone Swipe Gesture Recognizer (UISwipeGestureRecognizer) Swipe Left / Right / Up / Down
Rating :

 
iOS/iPhone Pan Gesture Recognizer (UIPanGestureRecognizer) Panning or dragging
Rating :

 
iOS/iPhone Pinch Gesture Recognizer (UIPinchGestureRecognizer) Pinching in and out (for zooming a view)
Rating :

 
iOS/iPhone Gesture and Image View Slide Show - (Objective-C , iPhone)
Rating :

 
iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer) Tap and Double Tap
Rating :

 
iOS/iPhone Long Press Gesture Recognizer (UILongPressGestureRecognizer)
Rating :


ThaiCreate.Com Forum
Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่