objective-c – iOS – 在iPad上动画UIView,同时改变x原点和宽度?

objective-c – iOS – 在iPad上动画UIView,同时改变x原点和宽度?,第1张

概述我在iPad上使用UIView动画遇到了一些麻烦. 我正在开发一个项目,在该项目中我使用JTRevealSidebar framework在左侧实现了“facebook风格”菜单. 然而,这个框架完美地运行,而不是将右侧视图“推”出屏幕,我想调整它的大小,因此用户仍然可以看到右侧视图的整个内容. 我设法通过更改视图的框架以及执行偏移来实现此目的. 这是侧边栏打开时的样子: 当它关闭时: 这个右侧视 我在iPad上使用UIVIEw动画遇到了一些麻烦.

我正在开发一个项目,在该项目中我使用JTRevealSidebar framework在左侧实现了“facebook风格”菜单.

然而,这个框架完美地运行,而不是将右侧视图“推”出屏幕,我想调整它的大小,因此用户仍然可以看到右侧视图的整个内容.

我设法通过更改视图的框架以及执行偏移来实现此目的.

这是侧边栏打开时的样子:

当它关闭时:

这个右侧视图包含一个带有两个按钮的导航栏(左侧有一个按钮可以切换左侧边栏,右侧有另一个按钮可以关闭控制器),内容本身就是一个简单的UIWebVIEw.

我面临的问题是在动画期间(从全屏状态到侧边栏打开状态):

当我更改视图的帧时,即使在执行转换后,视图也会在动画开始之前调整大小,这会产生如下奇怪的效果:

我想保持webvIEw的右侧固定在屏幕的右侧,并且在动画时只有左侧更改位置(基本上使“完成”按钮始终处于相同位置).

这是动画代码:

- (voID)revealSIDebar:(BOol)shouldReveal {    if (shouldReveal) {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.3];        // Push the vIEw to the right        contentVIEw.transform = CGAffinetransformTranslate(contentVIEw.transform,CGRectGetWIDth(sIDebarVIEw.frame),0);        // Resize the vIEw so it fits on remaining part of the screen        contentVIEw.frame = CGRectMake(contentVIEw.frame.origin.x,contentVIEw.frame.origin.y,contentVIEw.frame.size.wIDth-sIDebarVIEw.frame.size.wIDth,contentVIEw.frame.size.height);        // The problem is here: the vIEw's frame is changed before the        // Translate transformation actualy starts...        //        // Is there a way to change the x origin and the wIDth simultaneously ?        [UIVIEw commitAnimations];    } else {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.3];        // reset the frame so that it takes up whole screen        contentVIEw.frame = CGRectMake(contentVIEw.bounds.origin.x,contentVIEw.bounds.origin.y,contentVIEw.frame.size.wIDth+sIDebarVIEw.frame.size.wIDth,contentVIEw.frame.size.height);        [UIVIEw commitAnimations];    }    _state.isShowing = shouldReveal ? 1 : 0;}

到目前为止,我没有运气,如果有人对如何实现这一目标有任何想法,我就会徘徊.

谢谢

解决方法 编辑2:

似乎子视图正在立即调整使用的二重奏翻译.所以也许你可以动画向右移动,然后在完成后设置宽度

- (voID)animationDIDStop:(Nsstring *)animationID finished:(NSNumber *)finished context:(voID *)context {    contentVIEw.frame = CGRectMake(CGRectGetWIDth(sIDebarVIEw.frame),contentVIEw.frame.size.wIDth-CGRectGetWIDth(sIDebarVIEw.frame),contentVIEw.frame.size.height);}- (voID)animationDIDStopBack:(Nsstring *)animationID finished:(NSNumber *)finished context:(voID *)context {       contentVIEw.frame = contentVIEw.bounds;}- (voID)revealSIDebar:(BOol)shouldReveal {         if (shouldReveal) {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.1];        [UIVIEw setAnimationDelegate:self];        contentVIEw.frame = CGRectOffset(contentVIEw.bounds,0);        [UIVIEw setAnimationDIDStopSelector:@selector(animationDIDStop:finished:context:)];        [UIVIEw commitAnimations];    } else {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.3];        [UIVIEw setAnimationDelegate:self];    contentVIEw.frame = CGRectMake(0,contentVIEw.frame.size.wIDth+CGRectGetWIDth(sIDebarVIEw.frame),contentVIEw.frame.size.height);        [UIVIEw setAnimationDIDStopSelector:@selector(animationDIDStopBack:finished:context:)];        [UIVIEw commitAnimations];    }    _state.isShowing = shouldReveal ? 1 : 0;}

它并不完美,但确实避开了右侧的空白区域,因此我感觉看起来更好.特别是如果你加快动画.

编辑1:

尝试:

[UIVIEw beginAnimations:@"" context:nil];[UIVIEw setAnimationDuration:0.3];if (shouldReveal) {    contentVIEw.frame = CGRectMake(CGRectGetWIDth(sIDebarVIEw.frame),contentVIEw.frame.size.height);} else {    contentVIEw.frame = CGRectMake(0,contentVIEw.frame.size.height);}[UIVIEw commitAnimations];

旧答案:

声音/看起来你只需要修改x位置,始终位于侧边栏的边缘.假设您的contentvIEw的起源位于最左侧,未经测试的代码:

- (voID)revealSIDebar:(BOol)shouldReveal {    if (shouldReveal) {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.3];        // Push the vIEw to the right        contentVIEw.transform = CGAffinetransformTranslate(contentVIEw.transform,contentVIEw.frame.size.height);        [UIVIEw commitAnimations];    } else {        [UIVIEw beginAnimations:@"" context:nil];        [UIVIEw setAnimationDuration:0.3];        // Resize the vIEw so it fits on full screen        contentVIEw.frame = CGRectMake(sIDebarVIEw.frame.size.wIDth,contentVIEw.frame.size.height);        [UIVIEw commitAnimations];    }    _state.isShowing = shouldReveal ? 1 : 0;}

如果原点实际上居中,那么:

contentVIEw.frame = CGRectMake(sIDebarVIEw.frame.size.wIDth+(contentVIEw.frame.size.wIDth/2),contentVIEw.frame.size.height);
总结

以上是内存溢出为你收集整理的objective-c – iOS – 在iPad上动画UIView,同时改变x原点和宽度?全部内容,希望文章能够帮你解决objective-c – iOS – 在iPad上动画UIView,同时改变x原点和宽度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1082079.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存