ios training session-3

22

Upload: hussain-behestee

Post on 15-Jan-2015

593 views

Category:

Documents


0 download

DESCRIPTION

Programming with Segue Dynamic design through coding Views and its Co-ordinates Core animations Picture pickers Sound manager Address book picker - Hussain KMR Behestee

TRANSCRIPT

Page 1: iOS Training Session-3
Page 2: iOS Training Session-3

iOS Application Development

-Hussain KMR BehesteeThe Jaxara IT LTD.

[Session-3]

Page 3: iOS Training Session-3

Programming with Segue Dynamic design through coding

Views and its Co-ordinates

Core animations Picture pickers Sound manager Address book picker

Agendas

Page 4: iOS Training Session-3

Programming with Segue

Segue in Storyboarding

Page 5: iOS Training Session-3

Programming with Segue

What is Segue?

Page 6: iOS Training Session-3

Programming with Segue

Life Cycle of Segue

Your app never creates segue objects directly, they are always created on your behalf by iOS when a segue is triggered.

The destination controller is created and initialized. The segue object is created and its

initWithIdentifier:source:destination: method is called. The identifier is the unique string you provided for the segue in Interface Builder, and the two other parameters represent the two controller objects in the transition.

The source view controller’s prepareForSegue:sender: method is called.

The segue object’s perform method is called. This method performs a transition to bring the destination view controller on-screen.

The reference to the segue object is released, causing it to be deallocated.

Page 7: iOS Training Session-3

Programming with Segue

Triggering a segue programmatically

- (void)orientationChanged:(NSNotification *)notification{ UIDeviceOrientation deviceOrientation =

[UIDevice currentDevice].orientation;

if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];

isShowingLandscapeView = YES;

}}

Page 8: iOS Training Session-3

Dynamic design through coding

UIView's frame:

The CGPoint: The CGSize :

struct CGRect { CGPoint origin; CGSize size; };

struct CGPoint { CGFloat x; CGFloat y; };

struct CGSize { CGFloat width; CGFloat height; };

[button setFrame:CGRectMake(x, y, width, height)];

Page 9: iOS Training Session-3

Dynamic design through coding

Page 10: iOS Training Session-3

Creating UI Object on the flyUIImageView* campFireView =

[[UIImageView alloc] initWithFrame: self.view.frame];

campFireView.image = [UIImage imageWithName:@"image.png"];

Adding to view[self.view addSubview: campFireView];

Dynamic design through coding

Page 11: iOS Training Session-3

View Based Animation[UIView beginAnimations:nil context:NULL];[UIView setAnimationDuration:0.8];//animation logic here[UIView commitAnimations];

Set animation complete callback[UIView setAnimationDidStopSelector:

@selector(onAnimationComplete:finished:context:)];

onAnimationComplete – Callback- (void)onAnimationComplete:(NSString *)animationID

finished:(NSNumber *)finished context:(void *)context

Core animations

Page 12: iOS Training Session-3

Image Based Animation create the view that will execute our animation UIImageView* campFireView = [[UIImageView alloc]

initWithFrame:self.view.frame]; load all the frames of our animation campFireView.animationImages = [NSArray

arrayWithObjects:[UIImage imageNamed:@"campFire01.gif"],[UIImage imageNamed:@"campFire02.gif"], nil];

campFireView.animationDuration = 1.75; repeat the annimation forever campFireView.animationRepeatCount = 0; start animating [campFireView startAnimating]; add the animation view to the main window [self.view addSubview:campFireView];

Core animations

Page 13: iOS Training Session-3

Initialize the Image Picker and set delegate for interactionpicker = [[UIImagePickerController alloc] init];picker.delegate = self;

Checking and setting Source typeif ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){

picker.sourceType = UIImagePickerControllerSourceTypeCamera;} else{

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;}

Call the picker to front[self presentViewController:picker animated:YES completion:NULL];

Picture pickers

Initialization..

Page 14: iOS Training Session-3

If the user cancels we just dismiss the picker and release the object- (void)imagePickerControllerDidCancel:(UIImagePickerController *) Picker {

[[picker presentingViewController] dismissViewControllerAnimated:YES

completion:NULL];}

But if the user selects an image or takes a photo with the camera(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ {

selectedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

[[picker presentingViewController] dismissViewControllerAnimated:YES

completion:NULL];}

For more information

Picture pickers

Grabbing the image

Page 15: iOS Training Session-3

Get the main bundle for the appCFBundleRef mainBundle = CFBundleGetMainBundle ();

Get the URL to the sound file to playCFURLRef soundFileURLRef;soundFileURLRef = CFBundleCopyResourceURL

( mainBundle, CFSTR ("tap"), CFSTR ("aif"), NULL); Create a system sound object representing the sound

fileSystemSoundID soundFileObject;AudioServicesCreateSystemSoundID (soundFileURLRef,

&soundFileObject);

Sound manager

Page 16: iOS Training Session-3

For System Sound PlayAudioServicesPlaySystemSound

(soundFileObject); For Alert Sound Play

AudioServicesPlayAlertSound (soundFileObject); For Vibrate Play

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Sound manager

Page 17: iOS Training Session-3

Add Framework: AddressBookUI, AddressBook Add Header File: #import

<AddressBookUI/AddressBookUI.h> Add Protocol :

ABPeoplePickerNavigationControllerDelegate Responding to User Events

peoplePickerNavigationController:shouldContinueAfterSelectingPerson:

peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:

peoplePickerNavigationControllerDidCancel:

Address book picker

Page 18: iOS Training Session-3

Address book picker

Page 19: iOS Training Session-3

Address book picker

Page 20: iOS Training Session-3

Address book picker

Page 21: iOS Training Session-3

Address book picker

Page 22: iOS Training Session-3

Question?

ThanksThanks