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 –

関連する問題