For this look and feel you need in .h file :-
![]() | |
Nothing.png |
![]() | |
slideButton.png |
![]() | |
Container.png |
#import <UIKit/UIKit.h>
@interface SlideToUnlockViewController : UIViewController {
IBOutlet UISlider *slideToUnlock;
IBOutlet UIButton *lockButton;
IBOutlet UILabel *myLabel;
IBOutlet UIImageView *Container;
}
@property (nonatomic, retain) UISlider *slideToUnlock;
@property (nonatomic, retain) UIButton *lockButton;
@property (nonatomic, retain) UILabel *myLabel;
@property (nonatomic, retain) UIImageView *Container;
-(IBAction)UnLockIt;
-(IBAction)LockIt;
-(IBAction)fadeLabel;
@end
and in .m file :-
@synthesize slideToUnlock, myLabel, lockButton, Container;
BOOL UNLOCKED = NO;
- (void)viewDidLoad {
[super viewDidLoad];
// initialize custom UISlider (you have to do this in viewdidload or applicationdidfinishlaunching.
UIImage *stetchLeftTrack= [[UIImage imageNamed:@"Nothing.png"]
stretchableImageWithLeftCapWidth:30.0 topCapHeight:0.0];
UIImage *stetchRightTrack= [[UIImage imageNamed:@"Nothing.png"]
stretchableImageWithLeftCapWidth:30.0 topCapHeight:0.0];
[slideToUnlock setThumbImage: [UIImage imageNamed:@"SlideToStop.png"] forState:UIControlStateNormal];
[slideToUnlock setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[slideToUnlock setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
}
-(IBAction)LockIt {
slideToUnlock.hidden = NO;
lockButton.hidden = YES;
Container.hidden = NO;
myLabel.hidden = NO;
myLabel.alpha = 1.0;
UNLOCKED = NO;
slideToUnlock.value = 0.0;
NSString *str = @"The iPhone is Locked!";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Locked" message:str delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
}
-(IBAction)fadeLabel {
myLabel.alpha = 1.0 - slideToUnlock.value;
}
-(IBAction)UnLockIt {
if (!UNLOCKED) {
if (slideToUnlock.value ==1.0) { // if user slide far enough, stop the operation
// Put here what happens when it is unlocked
slideToUnlock.hidden = YES;
lockButton.hidden = NO;
Container.hidden = YES;
myLabel.hidden = YES;
UNLOCKED = YES;
}
else
{
// user did not slide far enough, so return back to 0 position
[UIView beginAnimations: @"SlideCanceled" context: nil];
[UIView setAnimationDelegate: self];
[UIView setAnimationDuration: 0.35];
// use CurveEaseOut to create "spring" effect
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
slideToUnlock.value = 0.0;
[UIView commitAnimations];
}
}
}
Hi Guys,
ReplyDeleteIs there a way of using this slide feature to initiate an animation.
e.g. Imagine if there was a padlock icon on the right hand side, and a key on the left hand side. I then slide from left to right and then the padlock icon would either open or do some other animation. to show that it has been unlocked.
Is this possible? and how could I do this?
Does anyone have an email address I can contact them on about this too?
Hello iBrade
DeletePlease drop me an email at adhikari.vijay05@gmail.com regarding to your animation detail, I try to make it work ..
Regards