1
팬 제스처 인식기를 통해 UIWindow
을 이동할 수 있습니까? 제스처가 작동하는 방식을 이해하는 데 문제가있어 창문이 아닌보기에서 작동하도록했습니다.UI 윈도우를 움직이는 데 팬 제스처를 사용할 수 있습니까?
팬 제스처 인식기를 통해 UIWindow
을 이동할 수 있습니까? 제스처가 작동하는 방식을 이해하는 데 문제가있어 창문이 아닌보기에서 작동하도록했습니다.UI 윈도우를 움직이는 데 팬 제스처를 사용할 수 있습니까?
예, 가능합니다.
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
안녕하세요, 답장을 보내 주셔서 감사합니다. 이로 인해 부분적으로 작동합니다. 그러나 시작점과 새로운 점 사이에서 점프하고 있습니다. 앤디 아이디어 왜? 마치 tryi로 설정 한 것입니다 –
@KaneBuckthorpe 답변을 업데이트했습니다. 다시 확인하실 수 있습니다. 그것이 작동하면 알려 주시기 바랍니다;) – trungduc
완벽하게 작동합니다! 고맙습니다! 이것은 나이 hahaa 동안 나를 괴롭혔다. –