get to an UIView frame a zoom animation

一曲冷凌霜 提交于 2019-12-05 23:48:39
Aaron Hayman

With the methodology you're currently using (not using a transform but simply resizing the view) you just need to reset the origin or center of the view). The easiest is the center:

 view.frame = CGRectMake(0, 0, 20, 20);
    CGPoint center = view.center;
    [UIView animateWithDuration: 1.0f animations:^{
        view.frame = CGRectMake(0, 0, 300, 300);
        view.center = center;
    }];

You can also reset the origin by moving subtracting 1/2 the difference of the size change from the x and y, but this is more math:

view.frame = CGRectMake(0, 0, 20, 20);
    CGPoint origin = view.frame.origin.
    [UIView animateWithDuration: 1.0f animations:^{
        origin.x -= (300 - 20) / 2;
        origin.y -= (300 - 20) / 2;
        view.frame = CGRectMake(origin.x, origin.y, 300, 300);
    }];

To make a view zoom out, while keeping it's own center is easy but you need to use transform. here is a code. Just add and connect a view, named it zoomerView.

In this example, I just add this to the main view touches ended.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    CGPoint center = zoomerView.center;
    [UIView animateWithDuration:1 animations:^{
        zoomerView.transform = CGAffineTransformScale(zoomerView.transform, 1.2, 1.2);
    }];
}

Hope this helps you

try this

[UIView animateWithDuration:secs delay:1.0 options:option
                     animations:^{
                         yourview.transform = CGAffineTransformScale(view.transform, 100.0, 100.0);
                     }
                     completion:nil]; 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!