У меня есть прокрутка CGRectMake(0, 0, 290, 266)
с изображением в нем.Изображение имеет такие функции, как масштабирование и масштабирование.Но когда я перетаскиваю изображение вниз или вверх, оно исчезает за прокруткой, оно не отображаетсяЯ хочу связать это изображение таким образом, чтобы оно не исчезало.
- (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];
}
}