设为首页 加入收藏

TOP

iOS 悬浮球效果实现,悬浮按钮,拖拽,贴边,隐藏,显示,旋转屏幕适配(五)
2023-07-23 13:26:37 】 浏览:453
Tags:iOS 拖拽 贴边 隐藏 显示
; SCREEN_WIDTH/2) {//悬浮窗在屏幕右侧 [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(ViewSize, self.center.y); }]; }else{ [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(SCREEN_WIDTH - ViewSize, self.center.y); }]; } } } self.alpha = 1; //三秒后隐藏悬浮窗,贴边展示一半 self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction) userInfo:nil repeats:NO]; } - (void)timerAction{ //隐藏悬浮球 self.alpha = 0.5; //判断是否移动过悬浮窗 if (!isChangePosition) { //悬浮窗初始位置在右上角,只有屏幕向右旋转,才需要留出iphone刘海的位置,设备左转刘海在左边,所以不需要做判断 if (self.orientation == UIInterfaceOrientationLandscapeLeft) {//横向home键在左侧,设备右转,刘海在右边 [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(SCREEN_WIDTH - [self vg_safeDistanceTop] - ViewSize - 20, self.center.y); }]; }else{ [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(SCREEN_WIDTH, 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, self.center.y); }]; }else{ //悬浮窗在屏幕左侧,留出刘海安全距离 [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake([self vg_safeDistanceTop] + ViewSize + 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, self.center.y); }]; }else{ [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(0, self.center.y); }]; } }else{ if (self.center.x > SCREEN_WIDTH/2) {//悬浮窗在屏幕右侧 [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(SCREEN_WIDTH, self.center.y); }]; }else{ [UIView animateWithDuration:0.5 animations:^{ self.center = CGPointMake(0, self.center.y); }]; } } } //销毁定时器 [self.timer invalidate]; self.timer = nil; } /// pan手势 /// @param recognizer recognizer description - (void)handlePanGesture:(UIPanGestureRecognizer *)recognizer { //移动状态 UIGestureRecognizerState recState = recognizer.state; isChangePosition = YES; switch (recState) { case UIGestureRecognizerStateBegan: self.alpha = 1; self.imageView.hidden = NO; break; case UIGestureRecognizerStateChanged://移动中 { self.alpha = 1; CGPoint translation = [recognizer translationInView:self]; recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); CGRect rect = [self convertRect:self.frame toView:self]; if (CGRectIntersectsRect(self.imageView.frame, rect)) {//在范围内 self.imageView.backgroundColor = UIColor.redColor; }else{ self.imageView.backgroundColor = UIColor.blueColor; } } break; case UIGestureRecognizerStateEnded://移动结束 { self.alpha = 0.5; CGPoint stopPoint = CGPointMake(0, SCREEN_HEIGHT / 2); //判断按钮贴靠在屏幕的左边还是右边 if (recognizer.view.center.x < SCREEN_WIDTH / 2) { stopPoint = CGPointMake(ViewSize/2, recognizer.view.center.y); }else{ //贴靠在右边 stopPoint = CGPointMake(SCREEN_WID
首页 上一页 2 3 4 5 6 下一页 尾页 5/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS 组件化实施过程 下一篇上架app store流程详解

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目