所以我用pageControl创建一个页面(它是一个带有多个视图的页面,带有指示您所在页面的点),我的代码如下所示viewDidLoad:
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
UIView *temp = [[UIView alloc]initWithFrame:self.view.frame];
temp.backgroundColor = [UIColor clearColor];
[temp addGestureRecognizer:swipe];
[self.view addSubview:temp];
Run Code Online (Sandbox Code Playgroud)
在swipeAction选择器中我有:
- (void)swipeAction: (UISwipeGestureRecognizer *)sender{
NSLog(@"Swipe action called");
if (sender.direction == UISwipeGestureRecognizerDirectionLeft) {
//Do Something
}
else if (sender.direction == UISwipeGestureRecognizerDirectionRight){
//Do Something Else
}
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,此方法仅在您向右滑动时起作用(即else if块被调用).当你向左滑动时,swipeAction甚至不会被召唤!这很奇怪,为什么会发生这种情况,我该如何更改代码?任何回复表示赞赏.非常感谢!
我正在尝试使用interactivepopgesturerecognizer返回一个视图,其中我还有一个带水平滚动的UICollectionView,问题是在集合视图的框架中,返回的滑动不起作用,但是工作时触摸开始于集合视图的框架之外,这是我的观点的一个示例:
| ---> here works
|-----------
|
| ---> This is the collection view and doesn't swipe to go back
|
|-----------
| ---> here works
Run Code Online (Sandbox Code Playgroud)
我怎么能解决这个问题?
编辑:我意识到这个问题只有在被推动的视图中才会出现导航栏被隐藏,并且当隐藏时,滑动返回不能在所有视图中不仅在集合视图中工作,并使其工作我需要添加此行:
[self.navigationController.interactivePopGestureRecognizer setDelegate:nil];
Run Code Online (Sandbox Code Playgroud)
在主视图中,但通过这种方式我无法滑动回到集合视图中.我创建了一个简单的测试来检查问题:
https://www.dropbox.com/s/c7ueyrcmm2x1m5w/TestSwipe.zip?dl=0
objective-c uiscrollview ios uiswipegesturerecognizer uicollectionview
我有一系列图像,我希望能够向前(向左)滑动到下一个图像,或向后(向右)滑动到上一个图像.当imageList达到-1 /超出范围时,应用程序崩溃.我无法弄清楚如何将其保持在范围内的逻辑.
这是我的代码:
var imageList:[String] = ["image1.jpg", "image2.jpg", "image3.jpg"]
let maxImages = 2
var imageIndex: NSInteger = 1
Run Code Online (Sandbox Code Playgroud)
滑动手势在我的viewDidLoad()方法中,不确定这是否是正确的位置......:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var swipeRight = UISwipeGestureRecognizer(target: self, action: "swiped:") // put : at the end of method name
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.view.addGestureRecognizer(swipeRight)
var swipeLeft = UISwipeGestureRecognizer(target: self, action: "swiped:") // put : at the end of method name
swipeLeft.direction = UISwipeGestureRecognizerDirection.Left
self.view.addGestureRecognizer(swipeLeft)
image.image = UIImage(named:"image1.jpg") …Run Code Online (Sandbox Code Playgroud) 我想在UITableView中添加两个手指向上和向下滑动手势.我们的想法是使用一个手指摇动手势滚动单元格,并使用两个手指向上/向下滑动手势来执行其他操作.我想为Tweetbot的夜间模式切换获得类似的体验:https://vine.co/v/hF5J1Y7hubT
这是我的代码:
func setupGestureRecognizer() {
swipeUp = UISwipeGestureRecognizer(target: self, action: "handleSwipe")
swipeDown = UISwipeGestureRecognizer(target: self, action: "handleSwipe")
swipeUp.direction = UISwipeGestureRecognizerDirection.Up
swipeDown.direction = UISwipeGestureRecognizerDirection.Down
swipeUp.numberOfTouchesRequired = 2
swipeDown.numberOfTouchesRequired = 2
self.tableView.panGestureRecognizer.maximumNumberOfTouches = 1
self.tableView.panGestureRecognizer.requireGestureRecognizerToFail(swipeUp)
self.tableView.panGestureRecognizer.requireGestureRecognizerToFail(swipeDown)
self.tableView.addGestureRecognizer(swipeUp)
self.tableView.addGestureRecognizer(swipeDown)
}
func handleSwipe() {
print("Swiped!")
let alert = UIAlertController(title: "Gesture recognizer", message: "Swipe detected", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
setupGestureRecognizer() 被称为 viewDidLoad()
当我用两根手指向上或向下滑动时,我会收到警报但是当我使用平移手势时,在桌子移动之前会有明显的延迟.这可能是泛手势需要等待以确保滑动手势失败的时间:
实际上对我来说更有意义requireGestureRecognizerToFail:swipeDown.requireGestureRecognizerToFail(self.tableView.panGestureRecognizer)但是当我尝试它时,滑动手势根本不起作用.我认为 …
uitableview uigesturerecognizer ios uiswipegesturerecognizer uipangesturerecognizer
我相信我找到了一个解决方案,但它是在Obj-C中我完全是新的并且很难将其解释为Swift:UIScrollView子视图中的水平UISwipeGestureRecognizer?(UIScrollView只需要识别垂直滚动)
我有我的Main.storyboard,它添加了两个子视图,我可以在它们之间水平滚动.目前,由于UIScrollView,检测到向上和向下滑动但不是左右滑动.任何解决方法这种干扰?
Main.storyboard:
// Global
let vc0 = ViewController0(nibName: "ViewController0", bundle: nil)
let vc1 = ViewController1(nibName: "ViewController1", bundle: nil)
class ViewController: UIViewController, UIScrollViewDelegate, UIGestureRecognizerDelegate {
@IBOutlet weak var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
self.addChildViewController(vc0)
self.scrollView.addSubview(vc0.view)
vc0.didMoveToParentViewController(self)
var frame1 = vc1.view.frame
frame1.origin.x = self.view.frame.size.width
vc1.view.frame = frame1
self.addChildViewController(vc1)
self.scrollView.addSubview(vc1.view)
vc1.didMoveToParentViewController(self)
self.scrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, self.view.frame.size.height - 66)
self.scrollView.delegate = self
// Swipe Gesture Recognizers
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.respondToSwipeGesture(_:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
let …Run Code Online (Sandbox Code Playgroud) I want to make a back swipe like the one in iOS 7.I'm still new with the whole iOS development, this is what I'm currently using.
Currently I have a pan gesture that detects if the user swipes back and then it just pops the navigation controller.
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.view addGestureRecognizer:pan];
-(void)handlePan:(UIPanGestureRecognizer *)sender{
CGPoint tran = [recognizer translationInView:recognizer.view];
CGPoint vel = [recognizer velocityInView:recognizer.view];
if(vel.x > 500 && tran.x > 100){
[self.navigationController popViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
I …
uinavigationcontroller ios uiswipegesturerecognizer uipangesturerecognizer ios7
func addSwipe() {
self.isUserInteractionEnabled = true
let directions: [UISwipeGestureRecognizerDirection] = [.right, .left]
for direction in directions {
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewCardContainer.handleSwipe(sender:)))
gesture.direction = direction
self.addGestureRecognizer(gesture)
}
}
@objc func handleSwipe(sender: UISwipeGestureRecognizer) {
print(sender.direction)
}
Run Code Online (Sandbox Code Playgroud)
我的UIViews:
+----------------+
| |
| +--------+ |
| V1 | V2 | |
+-----------------
Run Code Online (Sandbox Code Playgroud)
我在V2中注册了UISwipeGestureRecognizer但是如果从V1开始通过V2启动滑动手势,则在V2中将无法识别滑动手势.
反正有没有让它工作?提前致谢!
我试图通过苹果 PDFKit 库在 ios 上显示 pdf,而不是使用 PDFDisplayMode.singlePageContinuous 模式,我想在分页符处停止,所以我试图使用 PDFDisplayMode.singlePage。 https://developer.apple.com/documentation/pdfkit/pdfdisplaymode
但是,这种模式似乎只显示 pdf 的一页,这是非常无用的。我试过向页面添加滑动处理程序,但它们也不起作用。
我找到了示例应用程序并更改了它们的代码来测试 pdfdisplaymode 但遇到了同样的问题,例如 https://github.com/vipulshah2010/PDFKitDemo
如何使用 pdfkit 一次实现一页 pdfviewer,允许在页面之间滑动?!
我有UIViewController,我在故事板中添加了一个UITableView,后来我在视图中添加了一个向上滑动手势识别器,但没有任何反应.
这是我的代码
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate {
@IBOutlet weak var tableview: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let swipeRegongnizer = UISwipeGestureRecognizer(target: self, action: #selector(self.handleSwipeUp))
swipeRegongnizer.direction = UISwipeGestureRecognizerDirection.up
swipeRegongnizer.delegate = self
tableview.addGestureRecognizer(swipeRegongnizer)
}
func handleSwipeUp(gesture: UISwipeGestureRecognizer) {
print("swiped up")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let …Run Code Online (Sandbox Code Playgroud) 我需要检测所有向左滑动和向右滑动的滑动,包括向上滑动。我的意思是我需要检测 180 度区域内的所有滑动,我不确定我是否足够清楚。当我添加 .up .right 和 .left 时,它没有检测到像 left-up 这样的对角线,我该怎么办?谢谢!
ios ×9
swift ×5
uiscrollview ×2
uitableview ×2
arrays ×1
ios7 ×1
objective-c ×1
pdfkit ×1
singlepage ×1
swift3 ×1
swipe ×1
xcode ×1