计算滑动速度/速率的最佳方法是什么?是否有一些奇特的类或函数可以提供此功能,或者我是否需要通过测量触摸上升和下降来执行此操作?我做了一些搜索,但一无所获——也许我没有正确的术语。
我有一个自定义的 SwipeRefreshLayout,其中有一个自定义的 GridView。我想根据捏合/缩放手势更改 GridView 的列号。我已经成功实施了。问题是,尺度太敏感了。
例如,我的列号为 3-5。缩放到 3 或 5 很容易,但要缩放到 4 就很难了,因为缩放本身太敏感了。
这是我的自定义 SwipeRefreshLayout 类
/**
* This class contains fix from http://stackoverflow.com/questions/23989910/horizontalscrollview-inside-swiperefreshlayout
*/
public class CustomSwipeRefreshLayout extends SwipeRefreshLayout {
private int mTouchSlop;
private float mPrevX;
private ScaleGestureDetector mScaleGestureDetector;
private ScaleListener mScaleListener;
public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
public void setScaleListener(Context context, ScaleListener scaleListener) {
this.mScaleListener = scaleListener;
mScaleGestureDetector = new ScaleGestureDetector(context, new MyOnScaleGestureListener());
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mScaleGestureDetector …Run Code Online (Sandbox Code Playgroud) 我在视图中创建了一个 DragGesture,无论用户向左滑动还是向右滑动,它都应该选择一个 @State(Bool)。
问题是只检测到向右滑动。
如何使用 .gesture() 来捕捉用户是在他的屏幕上向左还是向右滑动?
import SwiftUI
struct SwiftUIView: View {
//MARK: Value to change on swipe gesture
@State var swipeRight: Bool
var body: some View {
VStack {
//MARK: Value displayed after user swiped
Text($swipeRight ? "Right" : "Left")
}
.gesture(
DragGesture()
.onChanged { (value) in
//MARK: What is it missing here?
switch value.location.x {
case ...(-0.5):
self.swipeRight = false
print("Swipe Left return false")
case 0.5...:
self.swipeRight = true
print("Swipe Right return true")
default: ()
}
}) …Run Code Online (Sandbox Code Playgroud) 我有一个按方块划分的屏幕,需要通过用手指连续触摸平移手势来改变它们的颜色。
起初,我认为我可以通过平移处理程序获取我手指的位置并找到哪个元素位于该位置来做到这一点,这样我就可以改变它的颜色。但它并没有像我想象的那样奏效。我被这个问题困住了,想知道你的意见。
我正在尝试让SwiftUI+ MapKit+LongPress手势正常工作。当我在 中添加地图时ContentView,效果很好。然后,我将.onLongPressGesture修改器添加到地图中,平移/缩放停止工作。长按虽然有效。
我正在处理的代码:
Map(coordinateRegion: $region, interactionModes: .all, showsUserLocation: true)
.onLongPressGesture {
// How do I get the location (Lat/Long) I am pressed on?
print("onLongPressGesture")
}
Run Code Online (Sandbox Code Playgroud)
另外,有没有办法从长按手势中获取纬度/经度?
希望使其SwiftUI仅使用即可工作,而不包含UIKit在UIViewRepresentable.
我使用react-native-gesture-handler和react-native-reanimated构建了捏合缩放效果。用户可以在图像的任意位置捏合,以手指之间的位置为缩放原点进行放大或缩小。这很棒。我遇到的问题是允许用户以多个捏合手势放大或缩小。这需要记住用户之前的捏合手势的偏移量和缩放比例。使用我当前拥有的代码,当用户第二次捏合时,手势处理程序会记住第一次捏合手势的缩放比例值,不会正确更新缩放原点。如何在不增加转换语句数量的情况下解决此问题?
const prevZoomScale = useSharedValue(1)
const currZoomScale = useSharedValue(1)
const zoomScale = useDerivedValue(() => { return prevZoomScale.value * currZoomScale.value }, [prevZoomScale.value, currZoomScale.value])
const tempZoomScale = useSharedValue(1)
const prevOriginOffset = useSharedValue({x: 0, y: 0})
const tempOriginOffset = useSharedValue({x: 0, y: 0})
const currOriginOffset = useSharedValue({x: 0, y: 0})
const pinchOriginOffset = useDerivedValue(() =>
{
return {
x: (prevOriginOffset.value.x + currOriginOffset.value.x),
y: (prevOriginOffset.value.y + currOriginOffset.value.y)
}
},
[prevOriginOffset.value.x, prevOriginOffset.value.y, currOriginOffset.value.x, currOriginOffset.value.y]
)
const onPinchEvent = useAnimatedGestureHandler<PinchGestureHandlerGestureEvent>({
onStart: (_) => {
prevZoomScale.value = …Run Code Online (Sandbox Code Playgroud) animation gesture react-native react-native-reanimated react-native-gesture-handler
我为新手问题道歉:
如何在phonegap应用程序中实现pinchzoom手势?我刚刚开始使用PhoneGap,一点教育不会伤害他!
日Thnx!
在我的viewDidLoad我设置
UISwipeGestureRecognizer *swipeRecognizerU = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeUpDetected:)]; swipeRecognizerU.direction = UISwipeGestureRecognizerDirectionUp; [self.view addGestureRecognizer:swipeRecognizerU];
Run Code Online (Sandbox Code Playgroud)
当我通过弹出窗口加载新视图时,我需要禁用该手势
// show popup view
-(IBAction)showPopup:(id)sender
{
MJDetailViewController *detailViewController = [[MJDetailViewController alloc] initWithNibName:@"MJDetailViewController" bundle:nil];
[self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideBottomBottom];
}
Run Code Online (Sandbox Code Playgroud)
在弹出视图被解除后,我需要设置滑动手势.
// hide popup view
-(IBAction)hidePopup:(id)sender
{
[self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationSlideBottomBottom];
}
Run Code Online (Sandbox Code Playgroud)
怎么做到这一点?
我想知道是否有一种Windows Phone的手势允许我点击一个按钮,然后拖动到另一个并点击它,当然没有XNA框架,因为这不是一个游戏,我不想使用它.
例如,我有两个按钮"A"和"B",如果点击A然后我在B上拖动我的手指(仍然在屏幕上),那么应该用A选择B.
我希望每个人都能理解我的问题,当然我正在用C#和XAML为Windows Phone 8做这一切.
谢谢你的回答.干杯.
我们如何在图像视图中旋转图像并在图像上应用手势,并将该图像以与图像相同的状态保存到服务器
- (IBAction)imageMove:(id)sender {
static int numRot = 0;
myimage.transform = CGAffineTransformMakeRotation(M_PI_2 * numRot);
++numRot;
}
Run Code Online (Sandbox Code Playgroud)
从这段代码我能够将我的图像视图旋转90度