AppLevelNotification:
AppDelegate.h:----
#import
@class Animations2ViewController;
@interface Animations2AppDelegate : NSObject {
UIWindow *window;
Animations2ViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Animations2ViewController *viewController;
-(void)appdelegateNotificationRecieved;
@end
AppDelegate.m:----
#import "Animations2AppDelegate.h"
#import "Animations2ViewController.h"
@implementation Animations2AppDelegate
@synthesize window;
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter]addObserver:viewController selector:@selector(notificationRecieved) name:@"maheshWokeUp" object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(appdelegateNotificationRecieved) name:@"maheshWokeUp" object:nil];
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
-(void)appdelegateNotificationRecieved{
NSLog(@"Appdelegate notificationr received");
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
Animations2ViewController.h:----
#import
@interface Animations2ViewController : UIViewController {
IBOutlet UIImageView *imgView;
IBOutlet UIButton *btn1;
IBOutlet UIButton *btn2;
}
-(IBAction)startAnimating;
-(IBAction)stopAnimating;
-(void)notificationRecieved;
@end
Animations2ViewController.m:----
#import "Animations2ViewController.h"
@implementation Animations2ViewController
-(void)notificationRecieved{
NSLog(@"notification recieved");
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
NSLog(@"device moved");
}
-(IBAction)startAnimating{
[imgView startAnimating];
}
-(IBAction)stopAnimating{
[[NSNotificationCenter defaultCenter]postNotificationName:@"maheshWokeUp" object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *img1= [UIImage imageNamed:@"1.jpg"];
UIImage *img2= [UIImage imageNamed:@"2-1.jpg"];
UIImage *img3= [UIImage imageNamed:@"2.jpg"];
UIImage *img4= [UIImage imageNamed:@"3.jpg"];
NSArray *arrImages =[[NSArray alloc]initWithObjects:img1,img2,img3,img4,nil];
imgView.animationImages =arrImages;
imgView.animationDuration =10;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
#import
@class Animations2ViewController;
@interface Animations2AppDelegate : NSObject
UIWindow *window;
Animations2ViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Animations2ViewController *viewController;
-(void)appdelegateNotificationRecieved;
@end
AppDelegate.m:----
#import "Animations2AppDelegate.h"
#import "Animations2ViewController.h"
@implementation Animations2AppDelegate
@synthesize window;
@synthesize viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter]addObserver:viewController selector:@selector(notificationRecieved) name:@"maheshWokeUp" object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(appdelegateNotificationRecieved) name:@"maheshWokeUp" object:nil];
// Override point for customization after app launch
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
-(void)appdelegateNotificationRecieved{
NSLog(@"Appdelegate notificationr received");
}
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
@end
Animations2ViewController.h:----
#import
@interface Animations2ViewController : UIViewController
IBOutlet UIImageView *imgView;
IBOutlet UIButton *btn1;
IBOutlet UIButton *btn2;
}
-(IBAction)startAnimating;
-(IBAction)stopAnimating;
-(void)notificationRecieved;
@end
Animations2ViewController.m:----
#import "Animations2ViewController.h"
@implementation Animations2ViewController
-(void)notificationRecieved{
NSLog(@"notification recieved");
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
NSLog(@"device moved");
}
-(IBAction)startAnimating{
[imgView startAnimating];
}
-(IBAction)stopAnimating{
[[NSNotificationCenter defaultCenter]postNotificationName:@"maheshWokeUp" object:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *img1= [UIImage imageNamed:@"1.jpg"];
UIImage *img2= [UIImage imageNamed:@"2-1.jpg"];
UIImage *img3= [UIImage imageNamed:@"2.jpg"];
UIImage *img4= [UIImage imageNamed:@"3.jpg"];
NSArray *arrImages =[[NSArray alloc]initWithObjects:img1,img2,img3,img4,nil];
imgView.animationImages =arrImages;
imgView.animationDuration =10;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
}
- (void)dealloc {
[super dealloc];
}
@end
0 comments:
Post a Comment