我正在尝试拖动视图,当拖动停止时,视图滑动到顶部并消失.我可以使用UIPanGestureRecognizer来拖动视图.但在那之后,我用动画让它滑出来.问题是,在拖动之后,在视图移动之前总是有一点打嗝......我四处搜索并且无法弄清楚如何解决这个问题.这是代码:
- (void)moveView2:(UIPanGestureRecognizer *)pan {
CGPoint delta = [pan translationInView:self.view];
CGPoint newCenter = CGPointMake(_view2.center.x, _view2.center.y + delta.y);
_view2.center = newCenter;
[pan setTranslation:CGPointZero inView:self.view];
if (pan.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [pan velocityInView:self.view];
NSLog(@"Velocity is %f, %f", velocity.x, velocity.y);
// Here is the delay
[UIView animateWithDuration:0.5 delay:0.0 usingSpringWithDamping:0.5f initialSpringVelocity:500 options:UIViewAnimationOptionCurveEaseInOut animations:^{
_view2.center = CGPointMake(_view2.center.x, -600);
} completion:nil];
}
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *fbButton;
@property (weak, nonatomic) IBOutlet UIButton *twitterButton;
@property UIView *view1;
@property UIView …Run Code Online (Sandbox Code Playgroud) 我是ios的新手,并且UIImageView我的内部viewController有限制.我也在使用autolayout这个应用程序.在某种情况下,我允许用户imageView使用Pan Gesture 移动.移动后是否需要更新该图像的约束?如果没有必要,我应该在移动后更新约束吗?如果对其中任何一个都是肯定的,那么更新约束的最有效方法是什么?
uigesturerecognizer ios uipangesturerecognizer autolayout swift
我有一个UIView和我使用下面的代码来实现它.
[myView setBackgroundColor:[UIColor redColor]];
[[myView layer] setCornerRadius:[myView bounds].size.height / 2.0f];
[[myView layer] setMasksToBounds:YES];
[myView setClipsToBounds:YES];
Run Code Online (Sandbox Code Playgroud)
然后添加 UIPanGestureRecognizer移动框
UIPanGestureRecognizer *panGesture=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(boxIsMoving:)];
[myView addGestureRecognizer:panGesture];
Run Code Online (Sandbox Code Playgroud)
但问题是当用户在该轮之外点击但在实际框架中并开始拖动我的视图也开始移动.任何人都可以建议我怎么能忽略这一轮之外的接触.
objective-c rounded-corners uigesturerecognizer ios uipangesturerecognizer
我正在使用平移手势识别器来关闭 UINavigationController。我正在使用此处的代码,并进行了修改以适合我的 NavigationController,我还将手势识别器添加到容器视图内的实际 VC。
一切正常,除了当我向下滑动时,导航栏会在 y 值 > 0.0 时更改其位置。
我认为正在发生的是导航栏附加到顶部安全区域,当它离开顶部安全区域时,它会自动将自身调整到视图的顶部。
我怎么能简单地实现它,以便导航栏的大小要么延伸到顶部的安全区域下方,要么完全忽略它,而是限制它所在的视图?
以下是图片:
这是我用于 UINavigationController 的代码
//
// PannableViewController.swift
//
import UIKit
class PannableViewController: UINavigationController {
public var minimumVelocityToHide = 1500 as CGFloat
public var minimumScreenRatioToHide = 0.5 as CGFloat
public var animationDuration = 0.2 as TimeInterval
override func viewDidLoad() {
super.viewDidLoad()
// Listen for pan gesture
let panGesture = UIPanGestureRecognizer(target: self, action: #selector(onPan(_:)))
if let lastVC = self.childViewControllers.last {
lastVC.view.addGestureRecognizer(panGesture)
}
}
func slideViewVerticallyTo(_ y: …Run Code Online (Sandbox Code Playgroud) uinavigationbar uinavigationcontroller ios uipangesturerecognizer swift
我使用本教程制作了一个适合任何视图控制器并显示在屏幕的一半上的 UIPresentationController 。现在我想添加阻力来消除这个问题。我试图让拖动感觉自然且响应灵敏,就像 Apple iOS 13 股票应用程序上“热门故事”的拖动体验一样。我认为 iOS 13 模式拖动关闭会被保留,但它不会转移到这个控制器,但事实并非如此。
我发现的每一点代码和教程都有糟糕的拖动体验。有谁知道如何做到这一点?过去一周我一直在尝试/寻找。先感谢您
这是我的演示控制器代码
class SlideUpPresentationController: UIPresentationController {
// MARK: - Variables
private var dimmingView: UIView!
//MARK: - View functions
override init(presentedViewController: UIViewController, presenting presentingViewController: UIViewController?) {
super.init(presentedViewController: presentedViewController, presenting: presentingViewController)
setupDimmingView()
}
override func containerViewWillLayoutSubviews() {
presentedView?.frame = frameOfPresentedViewInContainerView
}
override var frameOfPresentedViewInContainerView: CGRect {
guard let container = containerView else { return super.frameOfPresentedViewInContainerView }
let width = container.bounds.size.width
let height : CGFloat = 300.0
return CGRect(x: 0, y: container.bounds.size.height …Run Code Online (Sandbox Code Playgroud) draggable ios uipangesturerecognizer swift uipresentationcontroller
如何才能在使用 UIScrollView 时不调用平移手势识别器选择器。
我希望能够在不调用平移手势选择器的情况下在滚动视图中滚动。
这是我的平底锅检测功能:
- (void)panDetected:(UIPanGestureRecognizer *)panRecognizer
{
CGPoint translation = [panRecognizer translationInView:self.view];
CGPoint imageViewPosition = self.draggableImage.center;
imageViewPosition.x += translation.x;
imageViewPosition.y += translation.y;
self.draggableImage.center = imageViewPosition;
[panRecognizer setTranslation:CGPointZero inView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
当我在页面底部使用 UIScrollView 时,我不希望它被调用。
在我的iOS应用程序中,我有以下设置:
- (void)setupGestures
{
UIPanGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGesture:)];
[self.view addGestureRecognizer:panRecognizer];
UISwipeGestureRecognizer* swipeUpRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[swipeUpRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
[self.view addGestureRecognizer:swipeUpRecognizer];
}
// then I have following implementation of selectors
// this method supposed to give me the length of the swipe
- (void)panGesture:(UIPanGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan)
{
startLocation = [sender locationInView:self.view];
}
else if (sender.state == UIGestureRecognizerStateEnded)
{
CGPoint stopLocation = [sender locationInView:self.view];
CGFloat dx = stopLocation.x - startLocation.x;
CGFloat dy = stopLocation.y …Run Code Online (Sandbox Code Playgroud) 我正在使用平移手势识别器,我需要检测初始触摸点才能采取行动.我使用以下代码;
@IBAction func panDetected(sender: UIPanGestureRecognizer) {
let touchPoint = sender.locationOfTouch(0, inView: nil)
println(touchPoint.x)
}
Run Code Online (Sandbox Code Playgroud)
这些功能在我移动手指时打印触摸点.然而,一旦我从屏幕上抬起手指,它就会崩溃.这是崩溃消息;
Terminating app due to uncaught exception 'NSRangeException', reason: '-[UIPanGestureRecognizer locationOfTouch:inView:]: index (0) beyond bounds (0).'
Run Code Online (Sandbox Code Playgroud)
我已经尝试过设置最小和最大触摸限制,正如这篇文章所暗示的那样; 在iOS中查看触摸位置时,PAN手势会崩溃
可能是什么问题?
我想获得平移手势的速度,我想使用发送者的速度属性,但它似乎不起作用:
@IBAction func handleGesture(sender: AnyObject) {
let v = sender.velocity
}
Run Code Online (Sandbox Code Playgroud)
但它抛出一个错误说:
"ambiguous use of 'velocity'"
如果那不是获取平移手势速度的方式,那是什么?
这很奇怪,但当我添加UIPanGestureRecognizer一个视图时,它不起作用.这是我的观点,白色视图是红色视图的子视图:
主要观点:
@IBOutlet weak var redView: UIView!
@IBOutlet weak var whiteView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let panRecognizer = UIPanGestureRecognizer(target:self, action:#selector(ViewController.handlePan))
whiteView.gestureRecognizers = [panRecognizer]
}
func handlePan(recognizer:UIPanGestureRecognizer) {
//foo
}
Run Code Online (Sandbox Code Playgroud)
当我点击并拖动白色视图时,它将不会移动.