t;,NSStringFromCGPoint(lastPoint),NSStringFromCGPoint(self.center));
[self changeCoordinateScale];
}
//旋转屏幕后修改悬浮窗相对于屏幕的宽高比例以及坐标位置
- (void)changeCoordinateScale{
changeHig = self.center.y/SCREEN_HEIGHT;
changeWid = self.center.x/SCREEN_WIDTH;
//判断设备旋转方向
if (self.orientation == UIInterfaceOrientationLandscapeRight) {//横向home键在右侧,设备左转,刘海在左边,刘海在左边
//判断悬浮窗坐标x在屏幕的左边还是右边
if (self.center.x > SCREEN_WIDTH/2) {//大于中心x,在右边
//修改悬浮窗的坐标在最右边
self.center = CGPointMake(SCREEN_WIDTH, self.center.y);
}else{
//修改悬浮窗的坐标在最左边
self.center = CGPointMake([self vg_safeDistanceTop] + ViewSize + 20, self.center.y);
}
}else if(self.orientation == UIInterfaceOrientationLandscapeLeft){//横向home键在左侧,设备右转,刘海在右边
if (self.center.x > SCREEN_WIDTH/2) {//大于中心x,在右边
//修改悬浮窗的坐标在最右边,留出顶部安全距离
self.center = CGPointMake(SCREEN_WIDTH - [self vg_safeDistanceTop] - ViewSize - 20, self.center.y);
}else{
//修改悬浮窗的坐标在最左边
self.center = CGPointMake(0, self.center.y);
}
}else{
//大于中心x,在右边
if (self.center.x > SCREEN_WIDTH/2) {
self.center = CGPointMake(SCREEN_WIDTH, self.center.y);
}else{
self.center = CGPointMake(0, self.center.y);
}
}
// NSLog(@"changeHig == %f,changeWid == %f",changeHig,changeWid);
// NSLog(@"设备宽度 == %f, 设备高度== %f, 按钮坐标==%@",SCREEN_WIDTH,SCREEN_HEIGHT,NSStringFromCGPoint(self.center));
}
- (void)showSuspendView{
self.hidden = NO;
NSLog(@"显示悬浮窗");
}
- (void)dismissSuspendView{
self.hidden = YES;
NSLog(@"隐藏悬浮窗");
}
/// 悬浮窗按钮点击放法
/// @param button 点击之后完全显示悬浮窗,改变按钮位置
- (void)btnClick:(UIButton *)button{
if (self.delegate && [self.delegate respondsToSelector:@selector(suspendViewButtonClick:)]) {
[self.delegate suspendViewButtonClick:button];
}
// DLog(@"lastPoint == %@",NSStringFromCGPoint(lastPoint));
//如果没有改变过位置,lastPoint初始值(0,0)
//判断是否移动过悬浮窗
if (!isChangePosition) {
//悬浮窗初始位置在右上角,只有屏幕向右旋转,才需要留出iphone刘海的位置,设备左转刘海在左边,所以不需要做判断
if (self.orientation == UIInterfaceOrientationLandscapeLeft) {//横向home键在左侧,设备右转,刘海在右边
//修改点击后悬浮窗的位置,留出安全距离
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake(SCREEN_WIDTH - [self vg_safeDistanceTop] - ViewSize - 20 - 20, self.center.y);
}];
}else{
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake(SCREEN_WIDTH - ViewSize, self.center.y);
}];
}
}else{
// 判断最后的坐标是靠左还是靠右
if (self.orientation == UIInterfaceOrientationLandscapeRight) {//横向home键在右侧,设备左转,刘海在左边
if (self.center.x > SCREEN_WIDTH/2) {//悬浮窗在屏幕右侧
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake(SCREEN_WIDTH - ViewSize, self.center.y);
}];
}else{
//左转刘海在左边,留出安全距离
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake([self vg_safeDistanceTop] + ViewSize + 20 + 20, self.center.y);
}];
}
}else if(self.orientation == UIInterfaceOrientationLandscapeLeft){//横向home键在左侧,设备右转,刘海在右边
if (self.center.x > SCREEN_WIDTH/2) {//悬浮窗在屏幕右侧,留出刘海安全距离
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake(SCREEN_WIDTH - [self vg_safeDistanceTop] - ViewSize - 20 - 20, self.center.y);
}];
}else{//左侧显示
[UIView animateWithDuration:0.5 animations:^{
self.center = CGPointMake(ViewSize, self.center.y);
}];
}
}else{
if (self.center.x < |