Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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 用CGAffineTransform转换视图坐标_Iphone_Uiscrollview_Cgaffinetransform - Fatal编程技术网

Iphone 用CGAffineTransform转换视图坐标

Iphone 用CGAffineTransform转换视图坐标,iphone,uiscrollview,cgaffinetransform,Iphone,Uiscrollview,Cgaffinetransform,我在用TapToZoom应用程序胡闹,试图在缩放的图像上放置视图。我想做的是:双击,将图像旋转pi/2,将其放大8倍,然后将一个子视图放置在转换图像顶部的滚动视图中 我知道视图在原始坐标系中所需的帧。所以我需要在缩放后将这些坐标转换成新的系统 从ScrollViewSuite - (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer { // double tap zooms in float newScal

我在用TapToZoom应用程序胡闹,试图在缩放的图像上放置视图。我想做的是:双击,将图像旋转pi/2,将其放大8倍,然后将一个子视图放置在转换图像顶部的滚动视图中

我知道视图在原始坐标系中所需的帧。所以我需要在缩放后将这些坐标转换成新的系统

从ScrollViewSuite

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
    // double tap zooms in
    float newScale = [imageScrollView zoomScale] * 8;  // my custom zoom
    CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
    [imageScrollView zoomToRect:zoomRect animated:YES];
    [self rotateView:imageScrollView by:M_PI_2];      // then the twist
}
我的轮换代码

- (void)rotateView:(UIView *)anImageView by:(CGFloat)spin {

    [UIView animateWithDuration:0.5 delay: 0.0
                        options: UIViewAnimationOptionAllowUserInteraction 
                     animations:^{
                         anImageView.transform = CGAffineTransformMakeRotation(spin);
                     }
                     completion:^(BOOL finished){}];
}
然后,在缩放完成后,将视图放置在原始坐标系中的已知位置。这就是我想我需要帮助的地方

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)_scale {

    CGFloat coX = scrollView.contentOffset.x;
    CGFloat coY = scrollView.contentOffset.y;

    // try to build the forward transformation that got us here, then invert it
    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
    CGAffineTransform scale = CGAffineTransformMakeScale(_scale, _scale);

    // should these be negative?  some confusion here.
    CGAffineTransform translate = CGAffineTransformMakeTranslation(coX, coY);

    // what's the right order of concatenation on these?  more confusion
    CGAffineTransform aft0 = CGAffineTransformConcat(rotate, scale);
    CGAffineTransform aft1 = CGAffineTransformConcat(aft0, translate);

    // invert it
    CGAffineTransform aft = CGAffineTransformInvert(aft1);

    // this is the fixed rect in original coordinate system of the image
    // the image is at 0,0 320, 300 in the view, so this will only work
    // when the image is at the origin...  need to fix that later,too.
    CGRect rect = CGRectMake(248, 40, 90, 160);
    CGRect xformRect = CGRectApplyAffineTransform(rect, aft);

    // build a subview with this rect
    UIView *newView = [scrollView viewWithTag:888];
    if (!newView) {
        newView = [[UIView alloc] initWithFrame:xformRect];
        newView.backgroundColor = [UIColor yellowColor];
        newView.tag = 888;
        [scrollView addSubview:newView];
    } else {
        newView.frame = xformRect;
    }
    // see where it landed...
    NSLog(@"%f,%f  %f,%f", xformRect.origin.x, xformRect.origin.y, xformRect.size.width, xformRect.size.height);
}