static bool TextIsValidValue( NSString* newText, double &value )
{
bool result = false;
if ( [newText isMatchedByRegex:@"^(?:|0|[1-9]\\d*)(?:\\.\\d*)?$"] ) {
result = true;
value = [newText doubleValue];
}
return result;
}
- (IBAction) doTextChanged:(id)sender;
{
double value;
if ( TextIsValidValue( [i_pause stringValue], value ) ) {
[i_pause setTextColor:[NSColor blackColor]];
// do something with the value
} else {
[i_pause setTextColor:[NSColor redColor]];
}
}
Friday, December 9, 2011
iPhone how to check that a string is numeric only
Wednesday, August 10, 2011
Detecting direction of a swipe
Detecting direction of a swipe
MainView.h
Code:
#import
#import
@interface MainView : UIView {
IBOutlet UILabel *whataction;
CGPoint gestureStartPoint;
}
@end
MainView.m
Code:
#import "MainView.h"
@implementation MainView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
if (currentPosition.x - 30 > gestureStartPoint.x) {
[whataction setText:@"FAR RIGHT"];
}
else if (currentPosition.x > gestureStartPoint.x) {
[whataction setText:@"RIGHT"];
}
if (currentPosition.x + 30 < gestureStartPoint.x) {
[whataction setText:@"FAR LEFT"];
}
else if (currentPosition.x < gestureStartPoint.x) {
[whataction setText:@"LEFT"];
}
if (currentPosition.y - 30 > gestureStartPoint.y) {
[whataction setText:@"FAR DOWN"];
}
else if (currentPosition.y > gestureStartPoint.y) {
[whataction setText:@"DOWN"];
}
if (currentPosition.y + 30 < gestureStartPoint.y) {
[whataction setText:@"FAR UP"];
}
else if (currentPosition.y < gestureStartPoint.y) {
[whataction setText:@"UP"];
}
}
@end
MainView.h
Code:
#import
#import
@interface MainView : UIView {
IBOutlet UILabel *whataction;
CGPoint gestureStartPoint;
}
@end
MainView.m
Code:
#import "MainView.h"
@implementation MainView
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:self];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self];
if (currentPosition.x - 30 > gestureStartPoint.x) {
[whataction setText:@"FAR RIGHT"];
}
else if (currentPosition.x > gestureStartPoint.x) {
[whataction setText:@"RIGHT"];
}
if (currentPosition.x + 30 < gestureStartPoint.x) {
[whataction setText:@"FAR LEFT"];
}
else if (currentPosition.x < gestureStartPoint.x) {
[whataction setText:@"LEFT"];
}
if (currentPosition.y - 30 > gestureStartPoint.y) {
[whataction setText:@"FAR DOWN"];
}
else if (currentPosition.y > gestureStartPoint.y) {
[whataction setText:@"DOWN"];
}
if (currentPosition.y + 30 < gestureStartPoint.y) {
[whataction setText:@"FAR UP"];
}
else if (currentPosition.y < gestureStartPoint.y) {
[whataction setText:@"UP"];
}
}
@end
Monday, June 6, 2011
Cocos2d Menu
Menus
CCMenu * myMenu = [CCMenu menuWithItems:nil];
CCMenuItemImage *menuItem1 = [CCMenuItemImage itemFromNormalImage:@"myFirstButton.png"
selectedImage: @"myFirstButton_selected.png"
target:self
selector:@selector(doSomething:)];
[myMenu addChild:menuItem1];
[myMenu alignItemsVertically];
[self addChild:myMenu];
- (void) doSomething: (CCMenuItem *) menuItem
{
NSLog(@"The doSomething menu was called");
}
Cocos2d Basic and Scene Transition
Start From Here
http://cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_1._install_test
Api List
http://www.cocos2d-iphone.org/api-ref/latest-stable/index.html
Push Pop Scene
http://cocos2d-iphone.org/wiki/doku.php/prog_guide:lesson_1._install_test
Api List
http://www.cocos2d-iphone.org/api-ref/latest-stable/index.html
Push Pop Scene
[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];[[CCDirector sharedDirector] replaceScene: [SomeOtherScene scene]];
Fancy Transition List
[[CCDirector sharedDirector] replaceScene:
[CCTransitionFade transitionWithDuration:0.5f scene:[SomeOtherScene scene]]];
- CCTransitionFade
- CCTransitionFlipAngular
- CCTransitionShrinkGrow
- CCTransitionMoveInB
- CCTransitionMoveInT
- CCTransitionMoveInL
- CCTransitionMoveInR
- CCTransitionFadeTR
- CCTransitionFadeUp
- CCTransitionFlipX
- CCTransitionFlipY
- CCTransitionPageTurn
- CCTransitionCrossFade
Monday, April 11, 2011
Creating Basic Animations on iPhone
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView commitAnimations];
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView commitAnimations];
http://www.switchonthecode.com/tutorials/creating-basic-animations-on-iphone
Tuesday, February 22, 2011
Camera Iphone
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
imagePicker.allowsImageEditing = NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:@"Success"
message:@"Image saved to Photo Album."
delegate:self cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
Sunday, January 16, 2011
Iphone database samples
http://www.iphonesdkarticles.com/2008/10/sqlite-tutorial-selecting-data.html
Subscribe to:
Posts (Atom)