English 中文(简体)
通过CGAffine TransformScale计算的界限、框架和框架之间的不一致
原标题:Discrepancies between bounds, frame, and frame calculated through CGAffineTransformScale

我有一个简单的图像,在屏幕上贴上图像,使用户能够移动,并使用pin子和潘姿态识别器加以扩大。 在我的“全方位姿态”分配方法(规模)中,在我实际使用CGAffine TransformScale进行转变之前,Im试图计算变式框架的价值。 然而,我没有获得正确的价值,而且正在取得一些令人望而却步的结果,这种结果与应变的框架相吻合。 我的方法如下:

- (void)scale:(UIPinchGestureRecognizer *)sender 
{
    if([sender state] == UIGestureRecognizerStateBegan) 
    {
        lastScale = [sender scale];
    }

    if ([sender state] == UIGestureRecognizerStateBegan || 
        [sender state] == UIGestureRecognizerStateChanged) 
    {
        CGFloat currentScale = [[[sender view].layer valueForKeyPath:@"transform.scale"] floatValue];
        CGFloat newScale = 1 -  (lastScale - [sender scale]) * (CropThePhotoViewControllerPinchSpeed); 

        newScale = MIN(newScale, CropThePhotoViewControllerMaxScale / currentScale);   
        newScale = MAX(newScale, CropThePhotoViewControllerMinScale / currentScale);

        NSLog(@"currentBounds: %@", NSStringFromCGRect([[sender view] bounds]));
        NSLog(@"currentFrame: %@", NSStringFromCGRect([[sender view] frame]));

        CGAffineTransform transform = CGAffineTransformScale([[sender view] transform], newScale, newScale);
        CGRect nextFrame = CGRectApplyAffineTransform([[sender view] frame], transform);

        NSLog(@"nextFrame: %@", NSStringFromCGRect(nextFrame));

        //NSLog(@"nextBounds: %@", NSStringFromCGRect(nextBounds));

        [sender view].transform = transform;
        lastScale = [sender scale];

    } 
}

Here is a printed result I get:

/* currentBounds: {{0, 0}, {316, 236.013}} 
   currentFrame: {{-115.226,-53.4392}, {543.452, 405.891}} 
   nextFrame: {{-202.566, -93.9454}, {955.382, 713.551}} */

有了这些结果,目前的博恩座坐标显然与以往一样0,面积和宽度是原形象的大小和宽度,然后才能改变。 无论我有多少转变,这种价值似乎保持不变。

A. 现状 支离破碎是正确的坐标,也是根据它所改变的国家形象的目前状况确定的准确大小和宽度。

下次 框架是不正确的,应当与目前的框架相匹配。 从下一套印刷价值中支离破碎,但无。

因此,我有一些问题:

(1) 为什么现在 显示框架正确价值的脆弱性? 我认为,在你进行变革之后,框架是无效的? 这套价值观是在我与我的手在形象上所做的许多扩大和缩小规模之后表现出的。 看起来像现在的博爱的高峰和宽度一样是我对目前框架的期望。

2) 我的下一个框架价值为何被错误地计算,在我实际实施变革之前,我如何准确计算变框架的价值?

最佳回答

你们需要把新的转变运用到以下观点:untransform。 为此:

    CGAffineTransform transform = CGAffineTransformScale([[sender view] transform], newScale, newScale);
    CGAffineTransform iTransform = CGAffineTransformInvert([[sender view] transform]);
    CGRect rawFrame = CGRectApplyAffineTransform([[sender view] frame], iTransform);
    CGRect nextFrame = CGRectApplyAffineTransform(rawFrame, transform);
问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签