#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self beginGeneratingDeviceOrientationNotifications];
}
- (void)background {
UIImage *imageA = [UIImage imageNamed:@"123.png"];
CGSize imageSize = imageA.size;
CGFloat newWidth = (([[ UIScreen mainScreen ] bounds].size.height) / imageSize.height) * imageSize.width;
UIGraphicsBeginImageContext(self.view.frame.size);
[imageA drawInRect:CGRectMake(0, 0, newWidth, [[ UIScreen mainScreen ] bounds].size.height)];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:resizedImage];
}
- (void)beginGeneratingDeviceOrientationNotifications{
NSLog(@"it started");
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(deviceOrientationDidChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)deviceOrientationDidChangeNotification:(NSNotification*)note {
[self background];
NSLog(@"it changed");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
// UIGraphicsBeginImageContext(size);
// [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
// UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
// UIGraphicsEndImageContext();
// return destImage;
//}
@end
Comments