2010.07.12 // 이 글은 망했습니다. http://myriky.net/tc/124 를 참고하세요~

-------------------------------



어떤 외국인 아저씨가
UIScrollView를 이용한 샘플 코드를 올려달래서..

프로젝트도 다 끝났고, 시간도 널널한 관계로 한 번 만들어봤다..

근데 중요한 건.. Apple애들 사용하는 이미지 뷰어기능을 구현하기에는 좀 힘든 것 같다..

예를 들면, 두번 태핑했을 때 터치 된 좌표로 줌이 된다던가.. 그러한 메쏘드는 없는 것 같으니..


//
//  ScrollView.h
//  ScrollView
//
//  Created by Riky.G Kim on 09. 04. 22.
//  Copyright 2009 TSMobile. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ScrollView : UIScrollView <UIScrollViewDelegate> {
 UIImageView *SubImage;
 float  ZoomValue;
}
@end

//
//  ScrollView.m
//  ScrollView
//
//  Created by Riky.G Kim on 09. 04. 22.
//  Copyright 2009 TSMobile. All rights reserved.
//
#import "ScrollView.h"
@interface UIView (Gestures)   // undocumented SDK extension
- (void)zoomToScale:(float)scale;
- (void)rotateToDegrees:(float)degrees;
- (void)setRotationDegrees:(float)degrees duration:(NSTimeInterval)duration;
- (float)rotationDegrees;
- (void)setZoomScale:(float)scale duration:(NSTimeInterval)duration;
- (float)zoomScale;
@end
@implementation ScrollView
- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
  self.delegate = self;
  self.alwaysBounceHorizontal = YES;
  self.alwaysBounceVertical = YES;
  self.bounces = YES;
  self.bouncesZoom = YES;
  SubImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"missingtaiji.jpg"]] autorelease];
 
  ZoomValue = 100;
  CGSize ImageSize = SubImage.image.size;
 
  //minumum zoomscale of image
  while(ImageSize.width*(ZoomValue-1)/100>=320||ImageSize.height*(ZoomValue-1)/100>=460){
   ZoomValue--;
  }
  [self setContentSize:ImageSize];
  [self setMinimumZoomScale:ZoomValue/100];
 
  [self addSubview:SubImage];
 
 
    }
    return self;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
 return SubImage;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 UITouch *touch = [touches anyObject];
 if ([touch tapCount] == 2)
 {
  [SubImage setZoomScale:1.0 duration:0.0];
  [self setContentOffset:CGPointMake([touch locationInView:self].x*ZoomValue/100,[touch locationInView:self].y*ZoomValue/100)];
 }
 [super touchesBegan:touches withEvent:event];
}
@end


도움이 되길 바라며~
Creative Commons License
이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/04/23 10:11 2009/04/23 10:11

Trackback Address >> http://myriky.net/tc/trackback/87

댓글을 달아 주세요

  1. azki 2009/04/23 13:43  address  modify / delete  reply

    FF 에서는 코드가 안보임ㅡㅡ

  2. ㅇㅇ 2010/01/13 17:19  address  modify / delete  reply

    좋은 소스코드 갑사합니다. 복받으세요.

  3. d 2010/07/02 11:29  address  modify / delete  reply

    오류발견 ㅋㅋ

[로그인][오픈아이디란?]