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

Registered : 109,027

HOME > Mobile > [iOS/iPhone] Tutorials - สอนเขียน iPhone App ฟรี เขียน iPad App เรียน iPhone เขียนโปรแกรม iPhone > iOS/iPhone Pinch Gesture Recognizer (UIPinchGestureRecognizer) Pinching in and out (for zooming a view)



Clound SSD Virtual Server

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

iOS/iPhone Pinch Gesture Recognizer (UIPinchGestureRecognizer) Pinching in and out (for zooming a view) สำหรับ Pinch Gesture เป็น Gesture บน iOS ในรูปแบบของการ Zoom (ซูม) ด้วยการใช้นิ้วมือทั้งแต่ 2 นิ้วขึ้นไปในการที่จะ ขยายหรือย่อ รายการ View หรือ Object ต่าง ๆ บนหน้าจอ โดย Pinch Gesture จะใช้ Class ของ UIPinchGestureRecognizer ที่จะเข้ามาจัดการ Detect Gesture ที่เกิดขึ้น

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

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


Pinch Gesture (UIPinchGestureRecognizer) ที่เราเคยพบเจอกันบ่อย ๆ ก็เช่น App ที่ชื่อว่า Photos บน iPhone เมื่อเราคลิกเข้าไปในแต่ล่ะรูป เราสามารถที่จะทำการใช้ Pinch Gesture ในรูปแบบของ Zoom เพื่อย่อหรือขยายรูปภาพต่าง ๆ เหล่านั้นได้

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


Pinch Gesture Recognizer (UIPinchGestureRecognizer)
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    UIPinchGestureRecognizer *pinchGuesture = [[UIPinchGestureRecognizer alloc]
                                               initWithTarget: self
                                               action: @selector(pinGuestureHandle:)];
    [[self view] addGestureRecognizer:pinchGuesture];
}

-(void) pinGuestureHandle:(UIPinchGestureRecognizer *) sender {
    
    NSLog(@"Pin Gesture Handling");
    
}


Example การใช้ Pinch Gesture Recognizer (UIPinchGestureRecognizer) เพื่อ Zoom ขยาย-ลด ขนาด Font

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

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

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

เลือกและไม่เลือกดังรูป และให้เลิอก Create ตามลำดับ








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

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

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

ให้ทำการสร้าง Label และข้อความบน Label ด้วย String ดังรูป

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

ใน Class ของ .h ให้เชื่อม IBOutlet ของ Label ดังรูป

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

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

#import <UIKit/UIKit.h>

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

@end


ViewController.m
//
//  ViewController.m
//  pinchGesture
//
//  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.
    
    UIPinchGestureRecognizer *pinchGuesture = [[UIPinchGestureRecognizer alloc]
                                               initWithTarget: self
                                               action: @selector(pinGuestureHandle:)];
    [[self view] addGestureRecognizer:pinchGuesture];
}

-(void) pinGuestureHandle:(UIPinchGestureRecognizer *) sender {
    
    NSLog(@"Pin Gesture Handling");
    
    UIFont *font = lblString.font;
    CGFloat pointSize = font.pointSize;
    NSString *name = font.fontName;
    pointSize = ((sender.velocity > 0) ? 1 : -1) * 1 + pointSize;
    
    if (pointSize < 14)
        pointSize = 14;
    if (pointSize > 38)
        pointSize = 38;
    lblString.font = [UIFont fontWithName:name size:pointSize];
    
}

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

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









Screenshot

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

หน้าจอแรกของ View

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

การใช้ Pinch Gesture เพื่อ Zoom ในรูปแบบต่าง ๆ

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

การใช้ Pinch Gesture เพื่อ Zoom ในรูปแบบต่าง ๆ

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

การใช้ Pinch Gesture เพื่อ Zoom ในรูปแบบต่าง ๆ

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

แสดง NSLog ที่ได้เขียนดักไว้


.

   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-11-20 10:02:41 / 2017-03-26 09:53:26
  Download : Download  iOS/iPhone Pinch Gesture Recognizer  (UIPinchGestureRecognizer)  Pinching in and out (for zooming a view)
 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 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
   







Load balance : Server 00
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 อัตราราคา คลิกที่นี่