问题描述
我在视图中添加了UILongPressGestureRecognizer
,长按事件后,用户可以拖动视图.
I have added UILongPressGestureRecognizer
to a view, and after long press event, the user can drag the view.
我使用以下代码在关键窗口上添加了一个视图(需要导航和标签栏控制器上的自定义视图,这就是为什么需要在关键窗口上添加它):
I have added a view on the key window (need the custom view over the navigation and tab bar controllers, that is why need to add it on key window) using below code:
// add the custom view on the key window.
UIWindow *currentWindow = [UIApplication sharedApplication].keyWindow;
[currentWindow addSubview:customView];
现在,当我将第一个视图拖到 (screenSize/2)
点之外时,我希望 customView 从视图的右侧设置动画.我尝试了以下代码来呈现视图:
Now, when I am dragging the first view beyond the (screenSize/2)
point, I want the customView to animate from the right side of the view. I tried the following code to present the view:
// animate the customView view.
[UIView animateWithDuration:0.50f animations:^{
customView.frame = CGRectMake(SCREEN_WIDTH - customViewWidth, 0, customViewWidth, SCREEN_HEIGHT);
} completion:nil];
但是视图既没有出现也没有动画.我什至尝试使用 dispatch_async(dispatch_get_main_queue(),{});
但仍然没有成功.
But the view does not appear neither it animates. I even tried to use the dispatch_async(dispatch_get_main_queue(),{});
but still no success.
任何帮助将不胜感激.
推荐答案
你应该使用 UIAttachmentBehavior.
它指定了两个动态项之间或动态项和锚点之间的动态连接.当动态项目通过跟踪手势或通过其他输入移动时,任何附加的动态项目也会移动——如果可能的话,考虑到它的其他动态参数和边界.您可以使用附件的长度、阻尼和频率属性来配置附件行为.
It specifies a dynamic connection between two dynamic items, or between a dynamic item and an anchor point. When a dynamic item moves, either by tracking a gesture or via other input, any attached dynamic item also moves—if possible given its other dynamic parameters and boundaries. You can configure an attachment behavior using its length, damping, and frequency properties.
这篇关于使用 UILongPressGestureRecognizer 拖动另一个视图时在关键窗口上动画视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!