Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 可以使用平移手势移动窗口吗?_Ios_Cocoa Touch_Uiwindow - Fatal编程技术网

Ios 可以使用平移手势移动窗口吗?

Ios 可以使用平移手势移动窗口吗?,ios,cocoa-touch,uiwindow,Ios,Cocoa Touch,Uiwindow,是否可以通过平移手势识别器移动ui窗口?我在理解手势的工作原理方面遇到了一些问题,并设法使其在视图中工作,但在windows中却不工作。是的,你可以 UIWindow是UIView的子类,您可以正常添加PanGesture。若要移动窗口,请更改UIApplication.sharedApplication.delegate.window的框架,它将正常工作 创建一个新项目并用下面的“我的代码”替换AppDelegate.m文件。你们可以移动窗户 #import "AppDelegate.h"

是否可以通过平移手势识别器移动
ui窗口
?我在理解手势的工作原理方面遇到了一些问题,并设法使其在视图中工作,但在windows中却不工作。

是的,你可以

UIWindow
UIView
的子类,您可以正常添加
PanGesture
。若要移动窗口,请更改
UIApplication.sharedApplication.delegate.window的框架,它将正常工作

创建一个新项目并用下面的“我的代码”替换
AppDelegate.m
文件。你们可以移动窗户

#import "AppDelegate.h"

@interface AppDelegate ()

@property (nonatomic, strong) UIPanGestureRecognizer* panGesture;
@property (nonatomic, assign) CGPoint lastPoint;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.

  self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
  [self.window addGestureRecognizer:_panGesture];
  _needUpdate = YES;

  return YES;
}

- (void)handlePanGesture:(UIPanGestureRecognizer *)panGesture {
  CGPoint point = [panGesture locationInView:self.window];
  CGPoint center = self.window.center;

  if (CGPointEqualToPoint(_lastPoint, CGPointZero)) {
    _lastPoint = point;
  }

  center.x += point.x - _lastPoint.x;
  center.y += point.y - _lastPoint.y;
  self.window.frame = [UIScreen mainScreen].bounds;
  self.window.center = center;

  if (panGesture.state == UIGestureRecognizerStateEnded) {
    _lastPoint = CGPointZero;
  }
}


@end
是的,你可以

UIWindow
UIView
的子类,您可以正常添加
PanGesture
。若要移动窗口,请更改
UIApplication.sharedApplication.delegate.window的框架,它将正常工作

创建一个新项目并用下面的“我的代码”替换
AppDelegate.m
文件。你们可以移动窗户

#import "AppDelegate.h"

@interface AppDelegate ()

@property (nonatomic, strong) UIPanGestureRecognizer* panGesture;
@property (nonatomic, assign) CGPoint lastPoint;

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.

  self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
  [self.window addGestureRecognizer:_panGesture];
  _needUpdate = YES;

  return YES;
}

- (void)handlePanGesture:(UIPanGestureRecognizer *)panGesture {
  CGPoint point = [panGesture locationInView:self.window];
  CGPoint center = self.window.center;

  if (CGPointEqualToPoint(_lastPoint, CGPointZero)) {
    _lastPoint = point;
  }

  center.x += point.x - _lastPoint.x;
  center.y += point.y - _lastPoint.y;
  self.window.frame = [UIScreen mainScreen].bounds;
  self.window.center = center;

  if (panGesture.state == UIGestureRecognizerStateEnded) {
    _lastPoint = CGPointZero;
  }
}


@end

嘿,谢谢你的回复。这使它部分起作用。但它在起点和新起点之间跳跃。安迪,你知道为什么吗?好像要把它设定成both@KaneBuckthorpe我已经更新了答案。你可以再查一下。请让我知道它是否有效;)很好用!!非常感谢。这已经困扰了我很多年了哈哈,谢谢你的回复。这使它部分起作用。但它在起点和新起点之间跳跃。安迪,你知道为什么吗?好像要把它设定成both@KaneBuckthorpe我已经更新了答案。你可以再查一下。请让我知道它是否有效;)很好用!!非常感谢。这困扰了我好几年了哈哈