0

当用户可以从主视图中选择一个项目并将其拖到详细视图并放置它时,我正在使用拆分视图控制器。当用户拖动时,一个 UIView 会出现在详细视图的底部,如果他们在拖动过程中改变主意并想要删除它,他们可以在其中拖动该项目。我无法检测触摸何时在 UIView 中删除。这是我到目前为止所拥有的:

当用户在主控制器中选择项目时执行的代码。

主视图控制器:

    // Create pointer to window
    UIWindow *window = [UIApplication sharedApplication].delegate.window;

    // Create draggable view
    self.draggableImageView = [[UIImageView alloc] initWithImage:imageView.image];

    // Adapt to orientation
    [self.draggableImageView rotateToOrientation:[[UIApplication sharedApplication] statusBarOrientation]];

    // Hide detail calloutview if there is one
    [self.detailViewController hideCalloutView:NO];

    // Add drag-view to window
    CGPoint location = [gesture locationInView:gesture.view.window];
    [self.draggableImageView setCenter:location];
    [window addSubview:[self draggableImageView]];

    // Animate the marker to jump up
    [UIView animateWithDuration:0.10
                          delay:0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{

                         // Move the marker up
                         [self.draggableImageView setCenter:CGPointMake(location.x + 75.0f, location.y)];

    } completion:^(BOOL finished) {

    }];

    // Show our remove marker view
    [self.detailViewController showRemoveMarkerView];

当用户拖动时,详细视图控制器中的一个方法正在使用更新点调用,这是该方法中的代码:

- (void)pointForMarkerDidChange:(UIImageView *)imageView atPoint:(CGPoint)point
{
    NSLog(@"Point for Marker Did Change, point = %@", NSStringFromCGPoint(CGPointMake(point.x - 75.0f, point.y)));

    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    CGRect removeMarkerFrame = [window convertRect:self.removeMarkerView.frame fromView:self.view];

    if (CGRectContainsPoint(removeMarkerFrame, point)) {

        NSLog(@"YES");
    }
}

编辑:我更改了以下代码,现在可以使用。

- (void)pointForMarkerDidChange:(UIImageView *)imageView atPoint:(CGPoint)point
{
    UIWindow *window = [UIApplication sharedApplication].delegate.window;
    CGRect removeMarkerFrame = [self.removeMarkerView convertRect:self.removeMarkerView.round.frame toView:self.view];
    CGPoint point2 = [window convertPoint:point toView:self.view];

    if (CGRectContainsPoint(removeMarkerFrame, point2)) {

        NSLog(@"YES");
    }
}
4

0 回答 0