【发布时间】:2011-12-20 20:34:05
【问题描述】:
当您在我的应用程序中请求某些内容(例如按下按钮或其他任何内容)时,我希望实现这一点上滑效果”。我制作了一个简单的模型来很好地描述我想要实现的目标。你对我有什么暗示吗?谢谢。
注意:我不想拉动刷新效果(加载视图出现时屏幕不滚动,例如当您发送评论时出现)
更新:
我已经尝试过 Cirrostratus 代码:
- (IBAction)displayLoadingScreen:(id)sender
{
NSLog(@"pressed");
UIView *loadingView = [[UIView alloc] init];
loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,0,320,40);
}
completion:^(BOOL finished) {
}];
for (int i = 0; i < 10000; i++) {
NSLog(@"%d", i);
}
//animate out within some method called when loading ends
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,-40,320,40);
}
completion:^(BOOL finished){
}];
}
为什么加载视图在 for 循环之后滑动?如果你尝试一下,在它打印 for 循环之前和之后执行两个动画。想法?
更新 2
- (void)stopLoading {
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,-40,320,40);
}
completion:^(BOOL finished){
}];
}
- (void)startLoading {
loadingView.frame = CGRectMake(0,-40,320,40);
[loadingView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:loadingView];
//animate in within some method called when loading starts
[UIView animateWithDuration:1.0
animations:^{
loadingView.frame = CGRectMake(0,0,320,40);
}
completion:^(BOOL finished) {
}];
sleep(5);
[self stopLoading];
}
- (IBAction)displayLoadingScreen:(id)sender
{
NSLog(@"button pressed");
[self startLoading];
}
【问题讨论】:
-
尝试阅读
UIAnimation类(并使用 QuartzCore 框架)。 -
或者,如果您想像 Facebook 那样使用向下滑动更新功能,请考虑使用
EGOTableViewPullRefresh。
标签: iphone objective-c uiview core-animation uiviewanimation