2011-12-26 3 views
3

스크롤 뷰가 CGRectMake(0, 0, 290, 266)이고 이미지가 포함되어 있습니다. 이미지에는 확대/축소 및 확대/축소와 같은 기능이 있습니다. 그러나 이미지를 맨 아래 나 맨 위로 드래그하면 스크롤 뷰 뒤에서 사라져서 볼 수 없습니다. 사라지지 않는 방식으로 그 이미지를 묶고 싶습니다. 당신은 이미지 뷰의 프레임이 장치 화면 boundaries.To을 참조하여 변경됩니다 view.Then 이미지의 경계를 변경하는 스크롤하는 동안이 일이 일어날UIIcage의 UIImage

- (id)initWithFrame:(CGRect)frame 
{ 
    if ([super initWithFrame:frame] == nil) { 
     return nil; 
    } 

    appDelegate = (PostCart1AppDelegate*)[[UIApplication sharedApplication] delegate]; 
    originalSize = frame.size; 
    originalTransform = CGAffineTransformIdentity; 
    touchBeginPoints = CFDictionaryCreateMutable(NULL, 0, NULL, NULL); 
    self.userInteractionEnabled = YES; 
    self.multipleTouchEnabled = YES; 
    self.exclusiveTouch = YES; 

    return self; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSMutableSet *currentTouches = [[[event touchesForView:self] mutableCopy] autorelease]; 
    [currentTouches minusSet:touches]; 
    if ([currentTouches count] > 0) { 



     [self updateOriginalTransformForTouches:currentTouches]; 
     [self cacheBeginPointForTouches:currentTouches]; 
    } 
    [self cacheBeginPointForTouches:touches]; 
} 

CGPoint fr; 

-(BOOL)checkFrameinBounds:(TouchImageView *)t 
{ 

    float x = [touch1 locationInView:self].x; 
    float y = [touch1 locationInView:self].y;  
    NSLog(@"touch x = %f",x); 
    NSLog(@"touch y = %f",y); 


    if((fr.x < 30 || fr.y < 30) || (fr.x > 265 || fr.y > 240)) 
    { 
     NSLog(@" NO .. fr.x = %f",fr.x); 
     NSLog(@" NO .. fr.y = %f",fr.y); 
     return NO; 
    } 
    else 
    { 
     NSLog(@" YES .. fr.x = %f",fr.x); 
    NSLog(@" YES .. fr.y = %f",fr.y); 
     return YES; 
    } 

} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

    touch1 = [touches anyObject]; 
    fr=[[[event allTouches] anyObject] locationInView:self.superview]; 
    if ([self checkFrameinBounds:self]) 
    { 
    CGAffineTransform incrementalTransform = [self incrementalTransformWithTouches:[event touchesForView:self]]; 
    self.transform = CGAffineTransformConcat(originalTransform, incrementalTransform); 

    [self setConstrainedTransform:CGAffineTransformConcat(originalTransform, incrementalTransform)]; 
    } 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    if ([self checkFrameinBounds:self]) 
    { 

    for (UITouch *touch in touches) { 
     if (touch.tapCount >= 2) { 
      [self.superview bringSubviewToFront:self]; 
     } 
    } 

    [self updateOriginalTransformForTouches:[event touchesForView:self]]; 
    [self removeTouchesFromCache:touches]; 

    NSMutableSet *remainingTouches = [[[event touchesForView:self] mutableCopy] autorelease]; 
    [remainingTouches minusSet:touches]; 
    [self cacheBeginPointForTouches:remainingTouches]; 


    } 
} 
+0

어쩌면 이미지가 자동으로 렌더링됩니까? 그것을 유지하려고 했습니까? – Dimme

+0

예 이미지가 그대로 유지됩니다. 응용 프로그램이 손상되지 않습니다. 버 이미지가 사라졌습니다. – DipakSonara

+0

@DipakSonara 이미지의 드래그를 정확히 구현 한 방법은 무엇입니까? 코드를 제공해 주시겠습니까? – MadhavanRP

답변

0

이있는 ScrollView 안에 항상 이미지보기가 당신 이미지 뷰의 프레임을 변경해야하고 해당 프레임이 스크롤 뷰인 부모 뷰를 참조하여 변경됩니다.