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



Clound SSD Virtual Server

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

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer) Tap and Double Tap สำหรับ Tap Gesture บน iOS เป็นรูปแบบ Touch Screen ในรูปแบบของการคลิก หรือ Tap เป็นการกดลงบน หน้าจอของ Smart phone แล้วปล่อยมือ โดยเราสามารถเขียน Detect ดักจับ Event ของ Tap Gesture ในระดับ View หรือในระดับของแต่ล่ะ Object เรามาดูตัวอย่างการใช้ Tap Gesture (UITapGestureRecognizer) แบบง่าย ๆ

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

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


ใน Tap Gesture ที่ใช้งานบ่อย ๆ บน iOS ที่ได้พบเจอกันบน App ของ iPhone คือ Tap (การคลิกครั้งเดียว) และ Double Tap (การคลิก 2 ครั้ง) วิธีการดักจับ Detect ดูได้ตัวอย่างนี้

Tap Gesture Recognizer
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // for Tap
    UITapGestureRecognizer *oneTapGesture = [[UITapGestureRecognizer alloc]
                                             initWithTarget: self
                                             action: @selector(oneTapGestureHandle:)];
    [oneTapGesture setNumberOfTouchesRequired:1];
    [[self view] addGestureRecognizer:oneTapGesture];
}

- (void)oneTapGestureHandle:(UITapGestureRecognizer *)sender {
    NSLog(@"Tap Gesture Handling");
    lblResult.text = @"Tap Gesture Handling";
}


Double Tap Gesture Recognizer
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // for Double Tap
    UITapGestureRecognizer *twoTapGesture = [[UITapGestureRecognizer alloc]
                                             initWithTarget: self
                                             action: @selector(twoTapGestureHandle:)];
    [twoTapGesture setNumberOfTapsRequired:2];
    [twoTapGesture setNumberOfTouchesRequired:1];
    [[self view] addGestureRecognizer:twoTapGesture];
}

- (void)twoTapGestureHandle:(UITapGestureRecognizer *)sender {
    NSLog(@"Double Tap Gesture Handling");
     lblResult.text = @"Double Tap Gesture Handling";
}









Example การใช้ Tap Gesture (UITapGestureRecognizer) ตรวจสอบ Tap และ Double Tap

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

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

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

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

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

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

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

สร้าง Label บนหน้าจอ View

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

ใน Class ของ .h ทำการเชื่อม IBOutlet ของ Label








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

Screenshot

ViewController.h
//
//  ViewController.h
//  tapGesture
//
//  Created by Weerachai on 11/17/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UILabel *lblResult;
}

@end


ViewController.m
//
//  ViewController.m
//  tapGesture
//
//  Created by Weerachai on 11/17/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // for Tap
    UITapGestureRecognizer *oneTapGesture = [[UITapGestureRecognizer alloc]
                                             initWithTarget: self
                                             action: @selector(oneTapGestureHandle:)];
    [oneTapGesture setNumberOfTouchesRequired:1];
    [[self view] addGestureRecognizer:oneTapGesture];
    
    // for Double Tap
    UITapGestureRecognizer *twoTapGesture = [[UITapGestureRecognizer alloc]
                                             initWithTarget: self
                                             action: @selector(twoTapGestureHandle:)];
    [twoTapGesture setNumberOfTapsRequired:2];
    [twoTapGesture setNumberOfTouchesRequired:1];
    [[self view] addGestureRecognizer:twoTapGesture];
}

- (void)oneTapGestureHandle:(UITapGestureRecognizer *)sender {
    NSLog(@"Tap Gesture Handling");
    lblResult.text = @"Tap Gesture Handling";
}

- (void)twoTapGestureHandle:(UITapGestureRecognizer *)sender {
    NSLog(@"Double Tap Gesture Handling");
     lblResult.text = @"Double Tap Gesture Handling";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [lblResult release];
    [super dealloc];
}
@end




Screenshot

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

หน้าจอว่าง ๆ ยังไม่ได้ทำอะไร

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

เมื่อคลิกหรือ Tap ครั้งเดียว

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

เมื่อดับเบิ้ลคลิก Dobule Tap

iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)

เป็น Log ของ NSLog ที่ได้เขียนไว้

   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-11-20 10:00:58 / 2017-03-26 09:50:36
  Download : Download  iOS/iPhone Tap Gesture Recognizer (UITapGestureRecognizer)  Tap and Double Tap
 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 Rotation Gesture Recognizer (UIRotationGestureRecognizer)
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 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
   







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