objective-c - iOS:如何将视图与手指一起拖动到特定的 y 偏移?
问题描述
我正在使用平移手势从下到上拖动具有预定义偏移位置的视图。
我当前的实现是在手势结束后视图更新。但是,我希望视图与手指一起更新(手势正在进行)并在手势结束时停在预定义的(下一个)位置。
如果有人能指出我正确的方向,将不胜感激。谢谢你。
m_openPercentage = @"30,60";
- (void)onContentViewPanned:(UIPanGestureRecognizer *)gesture
{
CGPoint velocity = [gesture velocityInView:self.view];
NSArray *m_Openpercentage = [m_OpenPercentage componentsSeparatedByString:@","];
NSMutableArray *fullpercentage = [NSMutableArray arrayWithArray:m_Openpercentage];
float diffy = 0.0;
if(([gesture state] == UIGestureRecognizerStateEnded))
{
if(velocity.y < 0)
{
if(m_isfullscreen && ![fullpercentage containsObject:@"100"])
{
[fullpercentage addObject:@"100"];
}
diffy = 1-([[fullpercentage objectAtIndex:counter] floatValue]/100);
CGFloat ypos = self.view.frame.size.height * diffy;
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{
[self.view setNeedsLayout];
self.view.frame = CGRectMake(0,ypos,self.view.frame.size.width,self.view.frame.size.height);
if(self.view.frame.origin.y==0)
[self showNavigationbar:1];
} completion:^(BOOL finished) {
}];
if(counter<[fullpercentage count]-1)
counter++;
}
else
{
if(counter>0)
{
float diffy = 1-([[fullpercentage objectAtIndex:counter-1] floatValue]/100);
CGFloat ypos = self.view.frame.size.height * diffy;
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{
self.view.frame = CGRectMake(0,ypos,self.view.frame.size.width,self.view.frame.size.height);
} completion:^(BOOL finished) {
}];
}
else
{
diffy = 1-(m_initialPercentage/100);
CGFloat ypos = self.view.frame.size.height * diffy;
if(self.view.frame.origin.y < ypos)
{
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.5 options:0 animations:^{
self.view.frame = CGRectMake(0,ypos,self.view.frame.size.width,self.view.frame.size.height);
} completion:^(BOOL finished) {
}];
}
else
{
[self removeoverlayview];
[self.view removeFromSuperview];
id tmpControllerObj = [parentController getParentController];
[tmpControllerObj view].userInteractionEnabled = YES;
}
}
if((counter-1)>=0)
counter--;
[self showNavigationbar:0];
}
if(![m_Openpercentage containsObject:@"100"] && m_isfullscreen)
[self updatefullview];
}
}
解决方案
推荐阅读
- google-apps-script - 使用脚本编辑器将 Excel 文件从 Google Drive 复制到新创建的文件夹
- r - 使用 SLURM bash 脚本进行并行化和资源分配
- flutter - 使用 Positioned 小部件在 ListView.builder 项目小部件上添加小部件
- laravel - 获取徽标以显示在电子邮件标题中
- javascript - 如何在 IE 11 中实现扩展运算符?
- sql - Oracle 中的 IF ELSE 条件需要帮助
- neo4j - Neo4j 通过原生 api 创建索引的问题
- vb.net - 如何进行循环以查找匹配的字符串
- azure - 有没有办法在任务运行时(在完成之前)从 Azue Batch 任务中动态流式传输数据
- c# - 使用模型等待多个调用