Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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/iPad-核心动画-CGAffineTransformMakeTransform不';不要修改框架_Iphone_Ipad_Core Animation_Cgaffinetransform - Fatal编程技术网

iPhone/iPad-核心动画-CGAffineTransformMakeTransform不';不要修改框架

iPhone/iPad-核心动画-CGAffineTransformMakeTransform不';不要修改框架,iphone,ipad,core-animation,cgaffinetransform,Iphone,Ipad,Core Animation,Cgaffinetransform,我正面临一个非常恼人的问题。 这里是上下文:我有一个“矩形”视图,它是主视图的子视图。 我想做的很简单,当我点击一个按钮时,我希望“矩形”视图在x轴上平移,以便消失。然后,我添加一个新的子视图并对其进行转换,以取代以前的“矩形”视图。 它工作正常,只是如果我再次按下按钮,动画将从屏幕上开始,就像CGAffineTransformMakeTransform没有更改新“矩形”视图的帧一样。 代码如下: UIView *rectangleView = [detailView viewWithTag:4

我正面临一个非常恼人的问题。 这里是上下文:我有一个“矩形”视图,它是主视图的子视图。 我想做的很简单,当我点击一个按钮时,我希望“矩形”视图在x轴上平移,以便消失。然后,我添加一个新的子视图并对其进行转换,以取代以前的“矩形”视图。 它工作正常,只是如果我再次按下按钮,动画将从屏幕上开始,就像CGAffineTransformMakeTransform没有更改新“矩形”视图的帧一样。 代码如下:

UIView *rectangleView = [detailView viewWithTag:4]; //the actual frame is (20.0, 30.0, 884.0, 600.0)

[UIView animateWithDuration:0.5 animations:^{
    [rectangleView setTransform:CGAffineTransformMakeTranslation(-1000, 0)];
} completion:^(BOOL finished) {
    [rectangleView removeFromSuperview];
    UIView *otherView = [[UIView alloc] initWithFrame:CGRectMake(1020.0, 30.0, 884.0, 600.0)];
    [otherView setBackgroundColor:[UIColor purpleColor]];
    [otherView setTag:4];
    [detailView addSubview:otherView];
    [UIView animateWithDuration:0.5 animations:^{
        [otherView setTransform:CGAffineTransformMakeTranslation(-1000, 0)];
    } completion:^(BOOL finished) {
        [otherView release];
    }];
}];

尝试设置
center
属性的动画,而不是使用仿射变换。变换不是相加的,因此第二个动画(当新添加的细节视图移出屏幕时)实际上根本不会改变视图,因为它已经应用了平移(-1000,0)

添加第二个视图后,您已经将其变换设置为等于
cGraffineTransformMakeTransform(-1000,0)
,并且当您要删除该视图时,您设置了完全相同的变换,因此它将不起作用。这里有两个选项:

  • 将转换应用于视图已具有的变换:

    CGAffineTransform newTransform = CGAffineTransformConcat(rectangleView.transform, CGAffineTransformMakeTranslation(-1000, 0));
    [rectangleView setTransform:newTransform];
    
  • 不应用变换,而是直接使用视图位置操作(例如,通过其中心属性)


  • 它起作用了。非常感谢弗拉基米尔。我还有一个(也许是愚蠢的)问题。有没有办法测试视图是否有变换?有点像如果(![rectangleView transform])NSLog(@“没有转换,所以我不需要concat”)@Dave,您可以使用CgaffinetTransformityEntity函数检查视图的转换
    UIView *rectangleView = [detailView viewWithTag:4]; //the actual frame is (20.0, 30.0, 884.0, 600.0)
    CGAffineTransform tf = CGAffineTransformMakeTranslation(-1000, 0);
    [UIView animateWithDuration:0.5 animations:^{
        [rectangleView setCenter: CGPointApplyAffineTransform(rectangleView.center, tf)];
    } completion:^(BOOL finished) {
        [rectangleView removeFromSuperview];
        UIView *otherView = [[UIView alloc] initWithFrame:CGRectMake(1020.0, 30.0, 884.0, 600.0)];
        [otherView setBackgroundColor:[UIColor purpleColor]];
        [otherView setTag:4];
        [detailView addSubview:otherView];
        [UIView animateWithDuration:0.5 animations:^{
            [otherView setCenter: CGPointApplyAffineTransform(otherView.center, tf)];
        } completion:^(BOOL finished) {
            [otherView release];
        }];
    }];