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 Long Press Gesture Recognizer (UILongPressGestureRecognizer)

iOS/iPhone Long Press Gesture Recognizer (UILongPressGestureRecognizer) สำหรับ Log Press Gesture ของ iOS ในการเขียน App iPhone จะเป็นในลักษณะของการกดลงบนหน้าจอของ Smart Phone และแช่ไว้ซะครู่ อย่างน้อยประมาณ 1 วินาที หรือตามคุณสมัติของ minimumPressDuration ที่ได้กำหนดไว้ โดย Log Press Gesture จะใช้ Class ของ UILongPressGestureRecognizer เข้ามาจัดการในการตรวจสอบ Detect Gesture ที่เกิดขึ้น

iOS/iPhone Long Press Gesture Recognizer

iOS/iPhone Long Press Gesture Recognizer (UILongPressGestureRecognizer)


ในการสร้าง Gesture แบบ Long Press จะใช้ Class ของ UILongPressGestureRecognizer โดยเราสามารถกำหนดตัวหน่วงเวลา เปรียบเหมือน หน่วยเวลาวินาทีขั้นต่ำที่จะต้องกดหรือคลิกลงบนหน้าจอ ถึงจะเกิด Event ของ Log Press

Long Press Gesture Recognizer (UILongPressGestureRecognizer)
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    // Long  Press
    UILongPressGestureRecognizer *longPressGuesture = [[UILongPressGestureRecognizer alloc]
                                                       initWithTarget: self
                                                       action: @selector(longPressGuestureHandle:)];
    longPressGuesture.minimumPressDuration = 1;
    [[self view] addGestureRecognizer:longPressGuesture];
}

- (void)longPressGuestureHandle:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded ) {
        NSLog(@"Long Press Gesture Handling");
        lblResult.text = @"Long Press Gesture Handling";
    }
}


Example การสร้าง Long Press Gesture (UILongPressGestureRecognizer) แบบง่าย ๆ

iOS/iPhone Long Press Gesture Recognizer

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

iOS/iPhone Long Press Gesture Recognizer

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

iOS/iPhone Long Press Gesture Recognizer

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

iOS/iPhone Long Press Gesture Recognizer

ให้สร้าง Label บน View ดังรูป

iOS/iPhone Long Press Gesture Recognizer

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








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

ViewController.h
//
//  ViewController.h
//  longPressGesture
//
//  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
//  longPressGesture
//
//  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.
    
    // Long  Press
    UILongPressGestureRecognizer *longPressGuesture = [[UILongPressGestureRecognizer alloc]
                                                       initWithTarget: self
                                                       action: @selector(longPressGuestureHandle:)];
    longPressGuesture.minimumPressDuration = 1;
    [[self view] addGestureRecognizer:longPressGuesture];
}

- (void)longPressGuestureHandle:(UILongPressGestureRecognizer *)sender {
    if (sender.state == UIGestureRecognizerStateEnded ) {
        NSLog(@"Long Press Gesture Handling");
        lblResult.text = @"Long Press Gesture Handling";
    }
}

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

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


Screenshot

iOS/iPhone Long Press Gesture Recognizer

หน้าจอแรกของ App ตอนนี้ยังไม่ได้ทำอะไร








iOS/iPhone Long Press Gesture Recognizer

เมื่อคลิกลงบนหน้าจอแล้วทิ้งไว้ประมาณ 1 วินาที หรือตาม minimumPressDuration ที่ได้กำหนดไว้ ก็จะเกิด Event ของ Gesture Long Press

iOS/iPhone Long Press Gesture Recognizer

แสดง Log ที่ได้จาก NSLog

   
Share


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


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


   


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