[panRcognize setEnabled:YES];
[panRcognize delaysTouchesEnded];
[panRcognize cancelsTouchesInView];
[self addGestureRecognizer:panRcognize];
//监听屏幕旋转
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangeStatusBarOrientation)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
}
return self;
}
- (void)didChangeStatusBarOrientation {
self.orientation = [UIApplication sharedApplication].statusBarOrientation;
self.imageView.frame = CGRectMake((SCREEN_WIDTH - 50)/2, (SCREEN_HEIGHT - 50)/2, 50, 50);
// DLog(@"===%zd=====%zd",[[UIDevice currentDevice] orientation],[UIApplication sharedApplication].statusBarOrientation);
//请注意,UIInterfaceOrientationAndScapeLeft等于UIDeviceOrientation AndScapeRight(反之亦然)。
//这是因为向左旋转设备需要向右旋转内容。
/**
UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown,
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
*/
/**
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down
*/
switch ([UIDevice currentDevice].orientation)
{
case UIDeviceOrientationPortraitUpsideDown:
// DLog(@"设备倒垂直,home在上")
[self locationChange:@"Down"];
break;
case UIDeviceOrientationLandscapeLeft:{
// DLog(@"设备横屏,左转,home在右")
[self locationChange:@"left"];
}
break;
case UIDeviceOrientationLandscapeRight:{
// DLog(@"设备横屏,右转,home在左")
[self locationChange:@"right"];
}
break;
case UIDeviceOrientationPortrait:{
// DLog(@"设备垂直,home在下");
[self locationChange:@"Portrait"];
}
break;
default:
break;
}
}
//根据屏幕宽高改变按钮位置比例
- (void)locationChange:(NSString *)message{
// NSLog(@"changeHig == %f,changeWid == %f",changeHig,changeWid);
if (SCREEN_HEIGHT > SCREEN_WIDTH) {
//屏幕方向上
if ([message isEqualToString:@"Portrait"]) {
NSLog(@"安全区在上边");
self.center = CGPointMake(changeWid * SCREEN_WIDTH, changeHig * SCREEN_HEIGHT);
}else{//下
NSLog(@"安全区在下边");
self.center = CGPointMake(changeWid * SCREEN_WIDTH, changeHig * SCREEN_HEIGHT - [self vg_safeDistanceTop]);
}
}else{
if ([message isEqualToString:@"left"]) {//左
NSLog(@"安全区在左边");
self.center = CGPointMake(changeWid * SCREEN_WIDTH + [self vg_safeDistanceTop] + ViewSize, changeHig * SCREEN_HEIGHT);
}else{//右
NSLog(@"安全区在右边");
self.center = CGPointMake(changeWid * SCREEN_WIDTH - [self vg_safeDistanceTop] - ViewSize, changeHig * SCREEN_HEIGHT);
}
}
// NSLog(@"lastPoint == %@, self.center == %@&quo |