【发布时间】:2012-01-27 22:50:57
【问题描述】:
我有 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];
}
}
【问题讨论】:
-
也许图像会自动发布?您是否尝试保留它?
-
是的,我保留了图像。应用程序没有崩溃。 Bur 图像消失了。
-
@DipakSonara 您究竟是如何实现图像的拖动的?你能提供那个代码吗?
-
向我们展示您的代码,我们或许可以为您提供帮助。
-
请检查代码..我可能会得到解决方案..感谢您的时间。
标签: iphone ios uiscrollview