iPhone UIview动画调整大小就像消失在水中然后漂浮回来

发布于 2024-12-16 15:33:08 字数 357 浏览 2 评论 0原文

我不想像 uiview 动画的最常见解决方案那样淡入和淡出。我想让 uiview 调整为小,直到它消失并以相同的方式返回。另一种说法是,让相机靠近桌子,其中包含所有对象(UIView),并且相机向后移动,向后移动的越多,桌子就越小。这就是为什么我将其命名为“这主要是我的应用程序”,整个 uiview 沉入水中并浮起来。希望我能找到教程或某人的解决方案建议。所有内容都在屏幕的中间/中央调整大小/缩小。

更新*** 我希望它在屏幕的随机位置收缩并也从屏幕的随机位置出现。 另外,我来自其他类的子视图是 mainView 中的 viewdidload (View = [[View alloc] initWithFrame:CGRectMake(0, 40, 300, 300)];)

I don't want to fade in and fade out like most common solution for the uiview animation. I would like to have the uiview resize to small until it disappear and comes back the same way. Another way to say it is having a camera pointing closely at the table with all the object in it (UIView) and camera backs up and the more it backs up the smaller the table gets. Which is why i titled which is mainly my app the whole uiview sinks into the water and floats back up. Hopefully i'll find a tutorial or someone's suggestion for the solution. everything resize/shrinks in the middle/center of the screen.

UPDATE***
i would like it to shrink in random position of the screen and appear from random position of the screen also.
Also my subview from other class is viewdidload in mainView
(View = [[View alloc] initWithFrame:CGRectMake(0, 40, 300, 300)];)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往事随风而去 2024-12-23 15:33:08

试试这个,其中 view 是您正在处理的视图:

CGRect originalFrame = view.frame;

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
    CGRect frame = view.frame;
    frame.origin = view.center;
    frame.size = CGSizeMake( 0, 0 );
    view.frame = frame;
} completion:^(BOOL finished) {
    // Do something with the view

    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
        view.frame = originalFrame;
    } completion:^(BOOL finished) {
        return;
    }];

    return;
}];

Try this, where view is the view you are messing with:

CGRect originalFrame = view.frame;

[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
    CGRect frame = view.frame;
    frame.origin = view.center;
    frame.size = CGSizeMake( 0, 0 );
    view.frame = frame;
} completion:^(BOOL finished) {
    // Do something with the view

    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{
        view.frame = originalFrame;
    } completion:^(BOOL finished) {
        return;
    }];

    return;
}];
森罗 2024-12-23 15:33:08

您可以通过将框架缩小到屏幕上某个点中心的尺寸 (0,0) 来达到此效果

// assume float cx,cy are defined as center coordinates of your animation (ie where your image shrinks and grows from)
// assume CGRect animFrame is defined as the starting coordinates of your animationView
// assume you have outlet to animationView

// to shrink
        [UIView beginAnimations:@"WaterAnim" context:nil];
        [UIView setAnimationDuration:0.33];

        animationView.frame = CGRectMake(cx,cy, 0,0);

        [UIView commitAnimations];
// to grow
        [UIView beginAnimations:@"WaterAnim" context:nil];
        [UIView setAnimationDuration:0.33];
        animationView.frame = animationFrame;
        [UIView commitAnimations];

You can have that effect by shrinking the frame to size (0,0) over the center of some point on the screen

// assume float cx,cy are defined as center coordinates of your animation (ie where your image shrinks and grows from)
// assume CGRect animFrame is defined as the starting coordinates of your animationView
// assume you have outlet to animationView

// to shrink
        [UIView beginAnimations:@"WaterAnim" context:nil];
        [UIView setAnimationDuration:0.33];

        animationView.frame = CGRectMake(cx,cy, 0,0);

        [UIView commitAnimations];
// to grow
        [UIView beginAnimations:@"WaterAnim" context:nil];
        [UIView setAnimationDuration:0.33];
        animationView.frame = animationFrame;
        [UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文