标签: gesture

如何禁用 UICollectionView 的手势滑动

目前,我正在制作分页 UICollectionView。我想从 UICollectionView 禁用手势滑动效果,因为我要添加 UIPagerControl 来为分页 UICollectionView 设置动画。我不希望用户使用他们的手指移动到下一个屏幕而不是使用自定义 UIPageControl。

gesture uipagecontrol swipe ios uicollectionview

4
推荐指数
1
解决办法
2924
查看次数

检测通知托盘中的向左滑动?

我想检测用户何时在通知上向左滑动——它可以在任何通知上,因为我将使用通知侦听器检测最近解除了哪个通知。

是否有“全局”手势滑动我可以监听并且仅在我检测到我的通知被取消时触发我的特定于应用程序的事件?

notifications android gesture swipe

4
推荐指数
1
解决办法
2707
查看次数

SwiftUI:手势和偏移未按预期工作

我正在使用偏移量和手势修饰符在屏幕上移动一个圆圈。当我使用此代码时,一切都按预期工作:

import SwiftUI

struct MovingCircle: View {

@State private var dragged = CGSize.zero

var body: some View {
    Circle()
        .offset(x: self.dragged.width)
        .frame(width: 20, height: 20)
        .gesture(DragGesture()
            .onChanged{ value in
                self.dragged = value.translation
        }
        .onEnded{ value in
            self.dragged = CGSize.zero
            }
    )
 }
}
Run Code Online (Sandbox Code Playgroud)

但是,我不想将圆圈重置为 onEnded 的原始位置。我希望它保持原位,然后在拖动时再次移动。当我使用以下代码时,我无法在重新拖动时再次移动圆圈并且它保持原位:

import SwiftUI

struct MovingCircle: View {

@State private var dragged = CGSize.zero

var body: some View {
    Circle()
        .offset(x: self.dragged.width)
        .frame(width: 20, height: 20)
        .gesture(DragGesture()
            .onChanged{ value in
                self.dragged = value.translation
        }
        .onEnded{ value …
Run Code Online (Sandbox Code Playgroud)

offset gesture swiftui

4
推荐指数
1
解决办法
2648
查看次数

SwiftUI: DragGesture in ScrollView doesn't register scrolling when swipe begins on DragGesture view

So I have this really nice animation I want when a user presses a view, where it will sort of "bounce" under their finger as if it reacted to the touch.

Initial Goal

I need to register when the user presses down on the view (black rectangle in this example), so I can start shrinking it, then I need to register when they release on the view, so I can allow it to return to it's original size. User …

animation scrollview gesture swift swiftui

4
推荐指数
1
解决办法
2764
查看次数

onTapGesture 禁用我的选取器和分段点击

我正在创建一个Form使用SwiftUI. 在我的内部Form,我有一个DatePicker,,TextField和一个SegmentedPickerStyle

TextField正在使用 a .decimalPad,我正在尝试找到完成打字后关闭键盘的最佳方法。

我尝试添加 a.onTapGesture但它阻止我使用任何选择器。当我点击它们时什么也没有发生。

这是我正在尝试做的事情:

struct ContentView: View {
    @State var date = Date()

    @State var price = ""
    @State private var tipPercentage = 2

    let tipPercentages = [10, 15, 20, 25, 0]

    var body: some View {
            NavigationView {
                Form {
                    Section {
                        DatePicker(selection: $date, displayedComponents: .date) {
                            Text("Date").bold().foregroundColor(Color.init(red: 100.0/255.0, green: 208.0/255.0, blue: 100.0/255.0))
                        }

                        HStack {
                            Text("Price"))
                            Spacer() …
Run Code Online (Sandbox Code Playgroud)

picker gesture ios swiftui

4
推荐指数
1
解决办法
1976
查看次数

在 SwiftUI 中的 ForEach 内向图像添加拖动手势

我目前正在开发一个应用程序,向用户显示他的植物箱和一些测量值(如地面湿度、温度等)。每个植物箱里面都有一些植物,这些植物以详细视图显示。我希望用户能够将其中一株植物拖到角落以将其移除。目前我有这个实现:

@GestureState private var dragOffset = CGSize.zero

var body: some View {

    //Plants Headline
    VStack (spacing: 5) {
        Text("Plants")
            .font(.headline)
            .fontWeight(.light)

        //HStack for Plants Images
        HStack (spacing: 10) {

            //For each that loops through all of the plants inside the plant box
            ForEach(plantBoxViewModel.plants) { plant in

                //Image of the individual plant (obtained via http request to the backend)
                Image(base64String: plant.picture)
                    .resizable()
                    .clipShape(Circle())
                    .overlay(Circle().stroke(Color.white, lineWidth: 2))
                    .offset(x: self.dragOffset.width, y: self.dragOffset.height)
                    .animation(.easeInOut)
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 70, height: 70)
                    .gesture(
                           DragGesture()
                            .updating(self.$dragOffset, body: …
Run Code Online (Sandbox Code Playgroud)

gesture ios swift swiftui draggesture

4
推荐指数
1
解决办法
1792
查看次数

如何禁用捏放大android studio模拟器?

当我尝试使用 Android Studio 模拟器时,不小心点击了一些快捷方式会出现捏合缩放,我需要知道如何取消捏合缩放选项。

ubuntu android gesture android-emulator android-studio

4
推荐指数
1
解决办法
372
查看次数

在 Image SwiftUI 上点击动画

如何在图像上制作动画,以便当我点击它并按住它时它会向后缩放,当我释放它时图像会恢复到其原始大小?

struct ContentView: View {
    var body: some View {
        Image(systemName: "heart")
        .onTapGesture {
        // Gesture when held down and released
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

animation image gesture swift swiftui

4
推荐指数
1
解决办法
4794
查看次数

SwiftUI - 有没有办法向视图添加手势而不覆盖子视图的任何手势?

据我所知,在 SwiftUI 中从 TextField 中关闭键盘的唯一内置方法是按 Return 键。我想这样做,这样我就可以点击屏幕上除 TextView 之外的某个位置并关闭键盘。有一种方法可以这样做:

var body: some View {
  VStack(alignment: .center, spacing: 0) {
    Text("some text")
      .frame(maxWidth: .infinity)
      .contentShape(Rectangle())
      .onTapGesture(
        // dismiss keyboard here
      )

    TextField("text", $binding)

    Text("more text")
      .frame(maxWidth: .infinity)
      .contentShape(Rectangle())
      .onTapGesture(
        // dismiss keyboard here
      )
  }                  
}
Run Code Online (Sandbox Code Playgroud)

那就有点麻烦了。我想这样做:

var body: some View {
  VStack(alignment: .center, spacing: 0) {
    Text("some text")

    TextField("text", $binding)

    Text("more text")
  } 
  .frame(maxWidth: .infinity)
  .contentShape(Rectangle())
  .onTapGesture(
    // dismiss keyboard here
  )          
}
Run Code Online (Sandbox Code Playgroud)

这在大多数情况下都有效,但最外层视图上的手势会覆盖文本字段的手势。当您第一次按下文本字段时,键盘会显示,但是当您再次按下它时,它会消失,这是我不想要的。我希望子视图手势优先。如果 VStack 中有一个按钮,它应该只注册该按钮,而不注册关闭手势。我正在研究 GestureMask 和 ExclusiveGesture 但找不到方法。有没有人知道的方法?

gesture swiftui

4
推荐指数
1
解决办法
2355
查看次数

SwiftUI:放大手势可在最小值和最大值之间更改值

我想做与滑块相同的事情:

@State itemSize: CGFloat = 55.60

....

Text("ItemSize: \(itemSize)")
Slider(value: $itemSize, in: 45...120)
Run Code Online (Sandbox Code Playgroud)

但有放大手势。

我为此创建了修改器:

import SwiftUI

@available(OSX 11.0, *)
public extension View {
    func magnificationZoomer(value: Binding<CGFloat>,min: CGFloat, max: CGFloat) -> some View
    {
         self.modifier( MagnificationZoomerMod(minZoom: min, maxZoom: max, zoom: value) )
    }
}

@available(OSX 11.0, *)
public struct MagnificationZoomerMod: ViewModifier {
    let minZoom: CGFloat
    let maxZoom: CGFloat
    @Binding var zoom: CGFloat
    
    public func body (content: Content) -> some View
    {
        content
            .gesture(
                MagnificationGesture()
                    .onChanged() { val in
                        let magnification …
Run Code Online (Sandbox Code Playgroud)

macos gesture magnification swiftui

4
推荐指数
1
解决办法
914
查看次数