Skip to content

iOS应用内的悬浮按钮和工具条。(The float button and toolbar for app within iOS.)

License

Notifications You must be signed in to change notification settings

itenfay/DYFAssistiveTouchView

Repository files navigation

如果能帮助到你,请你给一颗星,谢谢!(If this can help you, please give it a star, Thanks!)

DYFAssistiveTouchView

实现应用内悬浮按钮和辅助工具条,可以增加/修改 Item 项,通过事件索引完成各种场景页面的跳转。

License MIT  CocoaPods  CocoaPods 

Installation

Using CocoaPods:

pod 'DYFAssistiveTouchView'

Or

 pod 'DYFAssistiveTouchView', '~> 4.3.1'

Group (ID:614799921)

Priview

Usage

  1. 实例化
// Lazy load
- (DYFAssistiveTouchView *)touchView {
    if (!_touchView) {
        _touchView = [[DYFAssistiveTouchView alloc] init];
        _touchView.frame = CGRectMake(0, 0, 50, 50);
    }
    return _touchView;
}
  1. 设置属性
  • 设置悬浮按钮的各种状态的图片
UIImage        *leftHidenImage = [UIImage imageNamed:@"atv_hide_left"];
UIImage       *rightHidenImage = leftHidenImage;
UIImage       *leftNormalImage = [UIImage imageNamed:@"atv_normal_left"];
UIImage      *rightNormalImage = leftNormalImage;
UIImage  *leftHighlightedImage = [UIImage imageNamed:@"atv_normal_left"];
UIImage *rightHighlightedImage = leftHighlightedImage;

self.touchView.touchObject.leftNormalImage       = leftNormalImage;
self.touchView.touchObject.rightNormalImage      = rightNormalImage;
self.touchView.touchObject.leftHighlightedImage  = leftHighlightedImage;
self.touchView.touchObject.rightHighlightedImage = rightHighlightedImage;
self.touchView.touchObject.leftTranslucentImage  = leftHidenImage;
self.touchView.touchObject.rightTranslucentImage = rightHidenImage;
  • 设置Unit对象
UIImage  *leftUint1Image = [UIImage imageNamed:@"atv_unit1_left"];
UIImage *rightUint1Image = [UIImage imageNamed:@"atv_unit1_right"];
UIImage  *leftUint2Image = [UIImage imageNamed:@"atv_unit2_left"];
UIImage *rightUint2Image = [UIImage imageNamed:@"atv_unit2_right"];

self.touchView.unitObject.leftTouchImage           = leftUint1Image;
self.touchView.unitObject.rightTouchImage          = rightUint1Image;
self.touchView.unitObject.leftItemBackgroundImage  = leftUint2Image;
self.touchView.unitObject.rightItemBackgroundImage = rightUint2Image;
  • 设置Item对象
UIImage *userImage = [UIImage imageNamed:@"atv_item_user"];
UIImage *cafeImage = [UIImage imageNamed:@"atv_item_cafe"];
UIImage   *csImage = [UIImage imageNamed:@"atv_item_cs"];

DYFAssistiveTouchItem *item  = [[DYFAssistiveTouchItem alloc] init];
item.image  = userImage;
DYFAssistiveTouchItem *item1 = [[DYFAssistiveTouchItem alloc] init];
item1.image = cafeImage;
DYFAssistiveTouchItem *item2 = [[DYFAssistiveTouchItem alloc] init];
item2.image = csImage;

self.touchView.items = @[item, item1, item2];
  1. 是否显示
[self.touchView isShowing]
  1. 显示
[self.touchView show];
  1. 隐藏
[self.touchView hide];
  1. 隐藏一半至屏幕
[self.touchView setShouldShowHalf:YES];
  1. 设置初始显示位置
[self.touchView setTouchViewPlace:DYFTouchViewAtMiddleRight];
  1. 响应事件(二选一)
- (void)presentAtIndex:(NSInteger)index {
    NSString *url = @"https://support.apple.com/zh-cn";

    if (index == 0) {
        url = @"https://github.com/itenfay";
    } 
    else if (index == 1) {
        url = @"https://github.com/itenfay/Awesome";
    } 
    else {
        url = @"https://www.jianshu.com/u/7fc76f1179cc";
    }

    SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:url]];
    [self presentViewController:safariVC animated:YES completion:NULL];
}
  • Block实现
- (IBAction)configureAction:(id)sender {
    if (!_touchView) {
        [self configTouchViewDotImages];
        [self configTouchViewUnits];
        [self configTouchViewItems];

        [self.touchView setShouldShowHalf:YES];
        [self.touchView setTouchViewPlace:DYFTouchViewAtMiddleRight];
        
        __weak typeof(self) weakSelf = self;
        [self.touchView touchViewItemDidClickedAtIndex:^(DYFAssistiveTouchView *touchView) {
            NSInteger index = touchView.indexOfItem;
            NSLog(@"Index of item: %zi", index);
            [weakSelf presentAtIndex:index];
        }];
    }
}
  • 代理实现
// 协议
Protocol: <DYFAssistiveTouchViewDelegate>

// 设置代理 
self.touchView.delegate = self;

// 代理实现
- (void)touchViewItemDidClickedAtIndex:(DYFAssistiveTouchView *)touchView {
    NSInteger index = touchView.indexOfItem;
    NSLog(@"Index of item: %zi", index);
    [self presentAtIndex:index]; 
}

Sample

About

iOS应用内的悬浮按钮和工具条。(The float button and toolbar for app within iOS.)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published