Giter Site home page Giter Site logo

dsmagnifierview's Introduction

DSMagnifierView

DSMagnifierView是一个有放大镜子效果的自定义控件。

先看效果:

放大镜效果

其实很简单,就是把UIWindow的图层给渲染到DSMagnifierView上。

由于这个放大镜要处于屏幕最上层,最好是UIWindow的子类,这样可以设置它的视图层级。

使用方法

1.初始化后设置用来渲染的视图renderView。

- (DSMagnifierView *)magnifierView {
    if (nil == _magnifierView) {
        _magnifierView = [[DSMagnifierView alloc] init];
        _magnifierView.renderView = self.view.window;
    }
    return _magnifierView;
}

2.在触摸屏幕的时候设置magnifierView的frame和渲染点renderPoint。

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];
    
    NSLog(@"touching");
    
    // 获取触摸点
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self.view];
    
    //window的hidden默认为YES
    self.magnifierView.hidden = NO;
    
    //设置magnifierView的frame
    self.magnifierView.frame = CGRectMake(0, 0, 150, 150);
    self.magnifierView.center = p;
    
    //设置渲染的中心点
    self.magnifierView.renderPoint = p;
}

3.用完后销毁

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];
    
    //用完一定要记得置nil。
    self.magnifierView = nil;
}

4.如果有任何疑问可以联系我,如果觉得对你有所帮助话给个Star✨吧!!🙂

dsmagnifierview's People

Contributors

derek547145012 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.