2017-11-12 3 views

답변

0

예, 가능합니다.

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 
+0

안녕하세요, 답장을 보내 주셔서 감사합니다. 이로 인해 부분적으로 작동합니다. 그러나 시작점과 새로운 점 사이에서 점프하고 있습니다. 앤디 아이디어 왜? 마치 tryi로 설정 한 것입니다 –

+0

@KaneBuckthorpe 답변을 업데이트했습니다. 다시 확인하실 수 있습니다. 그것이 작동하면 알려 주시기 바랍니다;) – trungduc

+0

완벽하게 작동합니다! 고맙습니다! 이것은 나이 hahaa 동안 나를 괴롭혔다. –

관련 문제