Animate a view on key window while dragging another view with UILongPressGestureRecognizer

核能气质少年 提交于 2019-12-13 19:18:15

问题


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];

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];

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.

Any help will be appreciated.


回答1:


You should use 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.



来源:https://stackoverflow.com/questions/29938813/animate-a-view-on-key-window-while-dragging-another-view-with-uilongpressgesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!