Coder Social home page Coder Social logo

lockscreen's Introduction

Lock Screen Example

This is a simple example showing how to create a lock screen in iOS.

This example uses Xibs. The storyboard version is forthcoming.

How it works

The main Xib contains two views; one for the mai UI and one for the UI that will be used as the lock overlay.

The main UI has a property for the lock overlay:

@property (strong, nonatomic) IBOutlet UIView *lockScreenView;

The File's Owner of the overlay view is set to this property in the Xib.

A second view is created in the main UI to handle the transparency portion of the overlay:

@interface MTViewController ()
    @property (strong, nonatomic) UIView *lockScreenCanvasView;
@end

@implementation MTViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    … setup ...
    self.lockScreenCanvasView = [[UIView alloc] initWithFrame:self.lockScreenView.bounds];
    self.lockScreenCanvasView.backgroundColor = [UIColor blackColor];
    [self.lockScreenCanvasView setAlpha:0.5];
}

When the Lock button is selected, the UI is changed like this:

- (void)lockScreen:(id)sender
{
    [self.view addSubview:self.lockScreenCanvasView];
    [self.view addSubview:self.lockScreenView];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

The navigation controller is hidden because the view overlay will not cover it and any buttons there will remain selectable.

The slider is hooked up to the main UI as follows:

- (IBAction)unlockSlider:(id)sender
{
    UISlider *uis = (UISlider*)sender;
    int sliderValue = (int)(uis.value + 0.5f);
    if (sliderValue == 100) {
        uis.value = 0.0f;
        [self.navigationController setNavigationBarHidden:NO animated:YES];
        [self.lockScreenCanvasView removeFromSuperview];
        [self.lockScreenView removeFromSuperview];
    } else {
        [UIView 
         animateWithDuration:0.35 
         delay:0 
         options:UIViewAnimationCurveEaseOut 
         animations:^{ uis.value = 0.0f; } 
         completion:NULL];
    }
}

This is the meat of the behavior. If the slider has been moved all the way to the right its value will be 100; this will trigger the restoration of the navigation controller and the lock views will be removed.

lockscreen's People

Contributors

iamthechad avatar

Watchers

Klovers.org 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.