1

我正在尝试像这样扩展我的视图:

CGRect endFrame = self.detailView.bounds;

[UIView animateWithDuration:0.25 animations:^{
    self.descriptionButton.bounds = endFrame;
}completion:^(BOOL finished) {
    self.containerView.alpha = 0.0;
    self.detailView.alpha = 1.0;
}];

我的 detailView 是容器视图。我的描述按钮在左上角。我想通过让按钮占据整个屏幕来提供放大效果。但是,默认情况下,Core Animation 从其中心的锚点缩放。

我尝试将锚点设置为视图图层的右下角,如下所示:

self.descriptionButton.layer.anchorPoint = CGPointMake(self.descriptionButton.bounds.size.width, self.descriptionButton.bounds.size.height);

CGRect endFrame = self.detailView.bounds;

[UIView animateWithDuration:0.25 animations:^{
    self.descriptionButton.bounds = endFrame;
}completion:^(BOOL finished) {
    self.containerView.alpha = 0.0;
    self.detailView.alpha = 1.0;
}];

但是当我这样做时,我根本看不到任何动画。有什么想法吗?谢谢。

4

2 回答 2

0

The anchorPoint property is "normalized" to values from 0 to 1. 0.5, 0.5 is the center. 0,0 is top left. 1,1 is bottom right.

Your code is setting the anchorPoint property using pixel coordinates, which is wrong. I don't know what it would do, but it's wrong.

于 2012-11-28T21:37:47.843 回答
0

你可以用一点数学

CGRect endFrame = self.detailView.frame;
CGRect currentFrame = self.detailView.frame;

[UIView animateWithDuration:0.25 animations:^
 {
     self.descriptionButton.frame = CGRectMake(currentFrame.x - (endFrame.size.width - currentFrame.size.width), currentFrame.y - (endFrame.size.height - currentFrame.size.height), endFrame.size.width, endFrame.size.height);
 }
                                 completion:^(BOOL finished)
 {
     self.containerView.alpha = 0.0;
     self.detailView.alpha = 1.0;
 }];
于 2012-11-28T17:52:05.413 回答