Slide To Unlock in an app! ~ heres how

Discussion in 'iOS Development' started by gojohnnyboi, Jun 10, 2008.

  1. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Ok, from new developers(including myself), i have heard many requests as to how to put a slide to unlock item in their application. I found out how!

    This is for all who WANT this info, for those who think i'm a rotten kid(Skylar), suck it up

    Please Register or Log in to view images


    I will just paste source code of a sample app i made to test it out.


    main.m
    Code:
    #import <UIKit/UIKit.h>
    #import "App.h"
    
    int main(int argc, char *argv[])
    {
    	NSAutoreleasePool* pool = [ [ NSAutoreleasePool alloc ] init];
    	return UIApplicationMain(argc, argv, [ App class ] );
    	[pool release];
    }
    RespringSlider.h
    Code:
    #import "Headers.h"
    #import <WebCore/WebFontCache.h>
    
    @interface RespringSlider : TPBottomLockBar
    {
    
    }
    
    - (id)initWithFrame:(CGRect)rect knobColor:(int)color label:(NSString*)label fontSize:(float)fsize;
    
    @end
    RespringSlider.m
    Code:
    #import "RespringSlider.h"
    
    @implementation RespringSlider
    
    - (id)initWithFrame:(CGRect)rect knobColor:(int)color label:(NSString*)label fontSize:(float)fsize
    {
    	if((self == [super initWithFrame: rect knobColor: color]) !=nil)
    		{
    			[self setFontSize: fsize];
    			[self setLabel:label];
    			[self startAnimating];
    		}
    	return self;
    }
    
    // Override the unlock method
    - (void)unlock 
    {
    	//[self freezeKnobInUnlockedPosition]; Not quite sure if this works, meh.
    	system("launchctl stop com.apple.SpringBoard");
    }
    
    @end
    App.h
    Code:
    #import "RespringSlider.h"
    
    @interface App : UIApplication
    {
    	RespringSlider* respringSlide;
    }
    
    @end
    App.m
    Code:
    #import "App.h"
    
    @implementation App
    
    - (void)applicationDidFinishLaunching:(id)unused
    {
    	CGRect rect = [ UIHardware fullScreenApplicationContentRect ];
    	rect.origin.x = 0.0f;
    	rect.origin.y = 0.0f;
    	
    	float blk[4] = { 0.0f, 0.0f, 0.0f, 255.0f };
    	
    	UIWindow* window = [ [ UIWindow alloc ] initWithContentRect: rect ];
    	[window _setHidden: false];
    	[window makeKey: self];
    	[window orderFront: self];
    	[window setBackgroundColor: CGColorCreate(CGColorSpaceCreateDeviceRGB(), blk)];
    	
    	UIView* mainView = [ [ UIView alloc ] initWithFrame: rect];
    	[window setContentView: mainView];
    	float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
    	
    	respringSlide = [ [ RespringSlider alloc ] initWithFrame: CGRectMake(0.0f, 364.0f, rect.size.width, 96.0f) knobColor:2 label:@"Restart SpringBoard" fontSize:19];
    	
    	TPLCDView* v = [ [ TPLCDView alloc ] initWithDefaultSize];
    	[ v setText:@"Slider Example"];
    	[ v setLabel:@"By Gojohnnyboi"];
    	[ mainView addSubview: v ];
    	
    	[mainView addSubview: respringSlide];
    	
    	
    }
    
    - (void)dealloc
    {
    	[respringSlide release];
    	[self dealloc];
    	[super dealloc];
    }
    
    @end
    makefile
    Code:
    CC=arm-apple-darwin-gcc
    LD=$(CC)
    LDFLAGS=	-lobjc \
    			-framework UIKit \
    			-framework Foundation \
    			-framework Celestial \
    			-framework CoreFoundation \
    			-framework GraphicsServices \
    			-framework WebCore \
    			-framework TelephonyUI \
    			-framework CoreGraphics
    App=SliderApp
    
    all:	$(App)
    
    $(App): main.o RespringSlider.o App.o
    	$(LD) $(LDFLAGS) -o $@ $^
    
    
    %.o:	%.m
    		$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    
    clean:
    		rm -f *.o $(App)

    Hope this helps somebody. I tweaked it a little bit to do what i wanted, meh.



    FOR THOSE WITH COMPILER ERRORS: You must first get the webfontcache.h file ( erica sadun's site ), and place it in your include directory under webcore
    -John
  2. Nickll9009

    Nickll9009 New Member

    Joined:
    Sep 19, 2007
    Messages:
    1,367
    Likes Received:
    8
    Device:
    iPod touch
    ty this will help me!
  3. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    =] hahah
  4. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    Sorry 4 double post.

    Notice also how you can change the text / font size of the highlighting text.

    You can also ( with a little reading of the TelephonyUI headers ), learn to create that highlighting text, just to use as text! it's pretty cool actually.

    It's - TPLockTextView
  5. hitman2992

    hitman2992 New Member

    Joined:
    Dec 10, 2007
    Messages:
    123
    Likes Received:
    0
    Device:
    iPhone 3GS (Black)
    very nice thank you
  6. cryptsucks

    cryptsucks Banned

    Joined:
    Mar 12, 2008
    Messages:
    683
    Likes Received:
    2
  7. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    np =)

    =)
  8. 101gfx

    101gfx New Member

    Joined:
    Jun 6, 2008
    Messages:
    349
    Likes Received:
    0
    Device:
    iPod touch
    Nice find. This should open new possibilities, I don't think however, that locking your iphone/touch while running an app is best for battery life.
  9. thesmidge

    thesmidge New Member

    Joined:
    Nov 22, 2007
    Messages:
    865
    Likes Received:
    31
    Device:
    3G iPod touch
    It doesn't only have to be for locking/unlocking. It could also be like in the MobilePhone.app's "slide to answer." But yeah, thanks very much for this, it'll help with the app I'm writing.
  10. The Ax

    The Ax Banned

    Joined:
    Mar 11, 2008
    Messages:
    647
    Likes Received:
    22
    Possible in Jiggy?

Share This Page