UIScrollview中的UIImage

UIScrollview中的UIImage

我有带有图像的CGRectMake(0, 0, 290, 266)的scrollview。图像具有缩放和缩放等功能。但是,当我将图像拖动到底部或顶部时,它消失在滚动视图的后面,因此无法查看。我想以不消失的方式绑定该图像。

- (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];


  }
}

最佳答案

这将在滚动时更改图像视图的边界时发生。然后,将根据设备屏幕边界更改图像视图的框架。要使图像视图始终位于滚动视图中,则必须更改图像框架。图像视图,则将参照其父视图(即scrollview)更改其框架。

关于iphone - UIScrollview中的UIImage,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8635343/

10-08 21:40