iOS Training Session-3

987 views

Published on

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

1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total views
987
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
18
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

iOS Training Session-3

  1. 1. iOS Application Development -Hussain KMR Behestee The Jaxara IT LTD. [Session-3]
  2. 2. Agendas∗ Programming with Segue∗ Dynamic design through coding ∗ Views and its Co-ordinates∗ Core animations∗ Picture pickers∗ Sound manager∗ Address book picker
  3. 3. Programming with SegueSegue in Storyboarding
  4. 4. Programming with SegueWhat is Segue?
  5. 5. Programming with SegueLife 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.
  6. 6. Programming with SegueTriggering a segue programmatically- (void)orientationChanged:(NSNotification *)notification{ UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; isShowingLandscapeView = YES; }}
  7. 7. Dynamic design through coding UIViews frame: The CGPoint: The CGSize : struct CGRect struct CGPoint struct CGSize { CGPoint origin; { CGFloat x; CGFloat { CGFloat width; CGSize size; }; y; }; CGFloat height; }; [button setFrame:CGRectMake(x, y, width, height)];
  8. 8. Dynamic design through coding
  9. 9. Dynamic design through coding∗ Creating UI Object on the fly UIImageView* campFireView = [[UIImageView alloc] initWithFrame: self.view.frame]; campFireView.image = [UIImage imageWithName:@"image.png"];∗ Adding to view [self.view addSubview: campFireView];
  10. 10. Core animations∗ 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
  11. 11. Core animations∗ 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];
  12. 12. Picture pickersInitialization..∗ Initialize the Image Picker and set delegate for interaction picker = [[UIImagePickerController alloc] init]; picker.delegate = self;∗ Checking and setting Source type if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ picker.sourceType = UIImagePickerControllerSourceTypeCamera; } else{ picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; }∗ Call the picker to front [self presentViewController:picker animated:YES completion:NULL];
  13. 13. Picture pickersGrabbing the image∗ 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
  14. 14. Sound manager∗ Get the main bundle for the app CFBundleRef mainBundle = CFBundleGetMainBundle ();∗ Get the URL to the sound file to play CFURLRef soundFileURLRef; soundFileURLRef = CFBundleCopyResourceURL ( mainBundle, CFSTR ("tap"), CFSTR ("aif"), NULL);∗ Create a system sound object representing the sound file SystemSoundID soundFileObject; AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);
  15. 15. Sound manager∗ For System Sound Play AudioServicesPlaySystemSound (soundFileObject);∗ For Alert Sound Play AudioServicesPlayAlertSound (soundFileObject);∗ For Vibrate Play AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
  16. 16. Address book picker∗ Add Framework: AddressBookUI, AddressBook∗ Add Header File: #import <AddressBookUI/AddressBookUI.h>∗ Add Protocol : ABPeoplePickerNavigationControllerDelegate∗ Responding to User Events ∗ peoplePickerNavigationController:shouldContinueAfterSelectingPerson: ∗ peoplePickerNavigationController:shouldContinueAfterSelectingPerson:pro perty:identifier: ∗ peoplePickerNavigationControllerDidCancel:
  17. 17. Address book picker
  18. 18. Address book picker
  19. 19. Address book picker
  20. 20. Address book picker
  21. 21. Question?Thanks

×