您正在将视图的中心设置为右上角。这意味着你正在放大中心左下角的某个位置。
试试这个
CGAffineTransform tr = CGAffineTransformScale(self.view.transform, 2, 2);
CGFloat h = self.view.frame.size.height;
[UIView animateWithDuration:2.5 delay:0 options:0 animations:^{
self.view.transform = tr;
self.view.center = CGPointMake(0,h);
} completion:^(BOOL finished) {}];
这将设置放大视图的左下角的中心,有效地拉近与固定右上角。
此代码没有硬编码的高度,这是一个更便携的(对iPhone 5的iPad)。
在设置transform
属性之前,您需要先保存h
,因为在此之后,您不应该依赖frame
的值。
编辑
为了让任何规模s
工作,使用此:
CGFloat s = 3;
CGAffineTransform tr = CGAffineTransformScale(self.view.transform, s, s);
CGFloat h = self.view.frame.size.height;
CGFloat w = self.view.frame.size.width;
[UIView animateWithDuration:2.5 delay:0 options:0 animations:^{
self.view.transform = tr;
self.view.center = CGPointMake(w-w*s/2,h*s/2);
} completion:^(BOOL finished) {}];
,使之成为左下角的工作,使用:
CGFloat s = 3;
CGAffineTransform tr = CGAffineTransformScale(self.view.transform, s, s);
CGFloat h = self.view.frame.size.height;
CGFloat w = self.view.frame.size.width;
[UIView animateWithDuration:2.5 delay:0 options:0 animations:^{
self.view.transform = tr;
self.view.center = CGPointMake(w*s/2,h-h*s/2);
} completion:^(BOOL finished) {}];
要使它适用于右下角,使用此:
CGFloat s = 3;
CGAffineTransform tr = CGAffineTransformScale(self.view.transform, s, s);
CGFloat h = self.view.frame.size.height;
CGFloat w = self.view.frame.size.width;
[UIView animateWithDuration:2.5 delay:0 options:0 animations:^{
self.view.transform = tr;
self.view.center = CGPointMake(w-w*s/2,h-h*s/2);
} completion:^(BOOL finished) {}];
参见:How to scale (zoom) a UIView to a given CGPoint
有关缩放到任意点什么?例如,为了响应用户点击屏幕? – user978838 2011-10-05 07:55:52