设为首页 加入收藏

TOP

iOS 悬浮球效果实现,悬浮按钮,拖拽,贴边,隐藏,显示,旋转屏幕适配(四)
2023-07-23 13:26:37 】 浏览:451
Tags:iOS 拖拽 贴边 隐藏 显示
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 <
首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS 组件化实施过程 下一篇上架app store流程详解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目