Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用CGPoint跟踪LongPress手势的准确位置_Iphone_Ios6_Cgpoint - Fatal编程技术网

Iphone 使用CGPoint跟踪LongPress手势的准确位置

Iphone 使用CGPoint跟踪LongPress手势的准确位置,iphone,ios6,cgpoint,Iphone,Ios6,Cgpoint,通过使用CGPoint location,它总是在uiscrollview中保存最后一幅图像。当我点击其他图像进行保存时。如何保存我点击的图像 UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; imageScrollView.pagingEnabled = YE

通过使用CGPoint location,它总是在uiscrollview中保存最后一幅图像。当我点击其他图像进行保存时。如何保存我点击的图像

UIScrollView *imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
imageScrollView.pagingEnabled = YES;

NSInteger numberOfViews = 61;

for (int i = 0; i < numberOfViews; i++) {

    CGFloat xOrigin = i * self.view.frame.size.width;

 NSString *imageName = [NSString stringWithFormat:@"image%d.png", i];

    _image = [UIImage imageNamed:imageName];

    _imageView = [[UIImageView alloc] initWithImage:_image];

    _imageView.frame = CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);

 UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc]
                                                       initWithTarget:self
                                                       action:@selector(handleLongPress:)];

    imageScrollView.userInteractionEnabled = YES;
    [imageScrollView addGestureRecognizer:gestureRecognizer];
    gestureRecognizer.delegate = self;
    [gestureRecognizer release];

    [imageScrollView addSubview:_imageView];
imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

    - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Save Photo", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet showInView:self.view];
    [actionSheet release];

     }}

 -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

switch (buttonIndex) {
    case 0:
        [self savePhoto];

       break;

    default:
        break;

}

   -(void)savePhoto{

CGPoint location = [gesture locationInView:_imageView];

if  (CGRectContainsPoint(_imageView.bounds, location)){

UIImageWriteToSavedPhotosAlbum(_image, self, @selector(image: didFinishSavingWithError:contextInfo:), nil);
   }}}
UIScrollView*imageScrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)];
imageScrollView.PaginEnabled=是;
NSInteger numberOfViews=61;
对于(int i=0;i
如有任何意见,将不胜感激


谢谢

该点将始终出现在触发
LongPressGestureRecognitor
UIScrollView
的范围内。您应该检查滚动视图的
contentOffset
(对于水平布局使用
contentOffset.x
,对于垂直布局使用
contentOffset.y
)检测应保存的图像

此外,您可以将接触点转换为
UIImageView
实例的局部坐标系,并查看该点是否位于图像视图的
边界内

更新

例如,您可以使用类似的方法来检测点是否在图像视图的边界内(注意:我没有测试过,这是假设有多个图像视图添加到滚动视图):


您还应考虑在用户将“<代码> uiActualPuths>代码>显示给用户之前,先保存哪一个图像并保存对该图像的引用,因为它可能会减少您可能遇到的潜在问题的数量,并且以后会更容易阅读,但这是我的主观看法。

这一点总是会显得机智。在触发长按识别器的

UIScrollView
的范围内。您应该检查滚动视图的
contentOffset
(对于水平布局,使用
contentOffset.x
,对于垂直布局,使用
contentOffset.y
)以检测应该保存的图像

此外,您可以将接触点转换为
UIImageView
实例的局部坐标系,并查看该点是否位于图像视图的
边界内

更新

例如,您可以使用类似的方法来检测点是否在图像视图的边界内(注意:我没有测试过,这是假设有多个图像视图添加到滚动视图):


您还应考虑在向用户显示 UIActudioP> <代码>之前,先保存哪些图像并保存对该图像的引用,因为它可能会减少您可能遇到的潜在问题的数量,并且稍后会更容易阅读,但这是我的主观看法。

当IMA时,如何将其放入代码中?在my UISCROLVIEW中,GE被放在一行中。在ScrollView中保存最后一幅图像时,没有同样的问题。当用户滚动图像时,您是否正在更改您的
\u image
ivar引用的图像?如果没有其他代码触及引用,则它将始终是其中存储的最后一幅图像,其中,f从上面的代码示例中,看起来是初始化视图层次结构的
for
循环。同样,您还需要确保当用户滚动内容时,
\u imageView
ivar正在更新。如果我可以用[imageView setTag:i]标记它们,然后用[scrollView viewWithTag:index+1]检索它们呢;这很有意义让您的
UIViewController
采用标题(.h)中的协议,将视图控制器设置为滚动视图的委托,然后在实现(.m)中实现
–scrollViewDidScroll:
方法。在
scrollViewDidScroll:
方法中,检查scroll视图的
contentOffset
属性,查看用户滚动了多少“页面”以检测当前显示的图像。如果将图像放在我的UIScrolView中的一行中,我如何将其放入代码中?保存最后一个im时,是否仍然存在相同的问题
if (CGRectContainsPoint(_imageView.bounds, [self.view convertPoint:location toView:_imageView]))
{
    // do something
}