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 Gesture and Image View Slide Show - (Objective-C , iPhone)

iOS/iPhone Gesture and Image View Slide Show - (Objective-C , iPhone) บทความนี้จะเป็นการใช้ Gesture ในการ Slide เปลี่ยนรูปภาพ Image View (UIImageView) เลื่อนซ้าย-ขวา โดยการใช้ Gesture ของ Swipe Gesture (UISwipeGestureRecognizer) ด้วยการ Swipe ไปทางซ้าย และ Swipe ไปทางขวา

iOS/iPhone Gesture and Image View Slide Show

iOS/iPhone Gesture and Image View Slide Show


สำหรับบทความนี้จะเป็นการ Apply การใช้งานจาก Swipe Gesture Recognizer (UISwipeGestureRecognizer) เพราะฉะนั้นแนะนำให้อ่านบทความนี้ก่อน

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


iOS/iPhone Gesture and Image View Slide Show

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

iOS/iPhone Gesture and Image View Slide Show

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

iOS/iPhone Gesture and Image View Slide Show

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

iOS/iPhone Gesture and Image View Slide Show

กลับมาในหน้า View ให้ทำการลาก Image View (UIimageView) เข้ามาบนหน้าจอ Design Interface

iOS/iPhone Gesture and Image View Slide Show

ใน Class ของ .h ให้ทำการเชื่อม IBOutlet ของ Image View (UIImageView)








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

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

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UIImageView *imgView;
}

@end


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

#import "ViewController.h"

@interface ViewController ()
{
    NSMutableArray *myObject;
    int i;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    i = 0;
    
    myObject = [[NSMutableArray alloc] init];
    [myObject addObject:@"girl1.jpg"];
    [myObject addObject:@"girl2.jpg"];
    [myObject addObject:@"girl3.jpg"];
    [myObject addObject:@"girl4.jpg"];
    
    
    imgView.image = [UIImage imageNamed:@"girl1.jpg"];
    
    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]
                                           initWithTarget:self
                                           action:@selector(swipeLeftHandle:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [[self view] addGestureRecognizer:swipeLeft];
    [swipeLeft release];
    
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]
                                            initWithTarget:self
                                            action:@selector(swipeRightHandle:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    [[self view] addGestureRecognizer:swipeRight];
    [swipeRight release];
}


-(void) swipeRightHandle:(UISwipeGestureRecognizer *) sender {
    if (sender.direction == UISwipeGestureRecognizerDirectionRight)
    {
        i = i - 1;
        if(i < 0)
        {
            i = myObject.count - 1;
        }
        
        NSString *arrValue = [myObject objectAtIndex:i];
        imgView.image = [UIImage imageNamed:arrValue];
        
        NSLog (@"%@" , [NSString stringWithFormat:@"Hello %@",arrValue]);
    }
}

-(void) swipeLeftHandle:(UISwipeGestureRecognizer *) sender {
    if (sender.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        i = i + 1;
        if(i >= myObject.count)
        {
            i = 0;
        }
        
        NSString *arrValue = [myObject objectAtIndex:i];
        imgView.image = [UIImage imageNamed:arrValue];
        
        NSLog (@"%@" , [NSString stringWithFormat:@"Hello %@",arrValue]);

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

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









Screenshot

iOS/iPhone Gesture and Image View Slide Show

แสดงรูปภาพ และสามารถใช้ Gesture ทำการ Slide ด้วยการ Swipe ไปด้านซ้าย-ขวา เพื่อเลื่อนรูปภาพต่าง ๆ

iOS/iPhone Gesture and Image View Slide Show

แสดงรูปภาพ

   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-11-20 10:03:07 / 2017-03-26 09:52:04
  Download : Download  iOS/iPhone Gesture and Image View Slide Show  - (Objective-C , iPhone)
 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 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 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 อัตราราคา คลิกที่นี่