[英]iOS UIView animation when table view scroll?
I want animation like home screen of this app .This screen has a view (with a label on it) on top and a table view under it. 我想要这个应用程序的主屏幕之类的动画。这个屏幕顶部有一个视图(上面有标签),下面有一个桌面视图。 When i scroll the table the top view and title on it become small with animation and after a specific point it becomes like navigation bar with title in centre.
当我滚动表格时,它的顶视图和标题变得很小,并且在特定点之后它变得像导航栏,标题位于中心。 And the same thing when i scroll down.
当我向下滚动时,同样的事情。 Here is what i tried so far
这是我到目前为止所尝试的
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint offset = scrollView.contentOffset;
NSLog(@"y is::: %f", offset.y);
if (offset.y > 0 && offset.y < 16 && self.topView.frame.size.height > 64) {
[UIView animateWithDuration:0.8 animations:^{
CGRect rect = self.topView.frame;
rect.size.height = rect.size.height-offset.y;
self.topView.frame = rect;
}completion:^(BOOL finish){
}];
}
else if(offset.y <= 0 && offset.y > -16 && self.topView.frame.size.height < 80)
{
[UIView animateWithDuration:0.8 animations:^{
CGRect rect = self.topView.frame;
rect.size.height = 80;
self.topView.frame = rect;
}completion:^(BOOL finish){
}];
}
}
Note that my top view initial height is 80 and i want to make it 64 when scroll up and vice versa. 请注意,我的顶视图初始高度为80,我想在向上滚动时使其为64,反之亦然。 with this code the view height animated but it depends upon animation duration.So if i scroll fast then it is not working properly.The original app i mentioned have very smooth animation.
使用此代码视图高度动画但它取决于动画持续时间。所以如果我快速滚动然后它不能正常工作。我提到的原始应用程序具有非常流畅的动画。 How could i achieve that?
我怎么能做到这一点? Screen shot of original App-
原创App-的屏幕截图
These screen shots showing three different scroll position, please note the "MySurgery" text on top.1- Larger text and right align.
这些屏幕截图显示了三个不同的滚动位置,请注意顶部的“MySurgery”文本.1-较大的文本和右对齐。 2- small text and near centre position 3- smaller text and centralised(like navigation bar)
2-小文本和近中心位置3-较小的文本和集中(如导航栏)
I think you dont need animation for this, you just need some calculations and setting frame of the top view. 我认为你不需要动画,你只需要一些计算并设置顶视图的框架。 like,
喜欢,
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint offset = scrollView.contentOffset;
if (offset.y>0 && offset.y<64) {
[topView layoutIfNeeded];
CGRect viewFrame = topView.frame;
viewFrame.size.height--;
topView.frame = viewFrame;
}
}
Note that layoutIfNeeded is required if your view is using autolayout 请注意,如果您的视图使用autolayout,则需要layoutIfNeeded
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.