我的代码有问题,在我开始添加 myImageView 代码之前它工作正常,但是 appDelegate 不完整的实现警告已经存在很长时间了。
我的 appDelegate.h
//
// AppDelegate.h
// drawern
//
// Created by Marin Jelica on 2012-11-21.
// Copyright (c) 2012 Marin Jelica. All rights reserved.
//
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate/*, UIScrollViewDelegate*/>
/*{
// IBOutlet UIScrollView *myScrollView;
// UIImageView *myImageView;
}*/
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
/*
@property (strong, nonatomic) UIScrollView *myScrollView;
@property (strong, nonatomic) UIImageView *myImageView;
*/
-(void)setRed;
-(void)setGreen;
-(void)setBlue;
@end
我的 appDelegate.M
//
// AppDelegate.m
// drawern
//
// Created by Marin Jelica on 2012-11-21.
// Copyright (c) 2012 Marin Jelica. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
@implementation AppDelegate
//@synthesize myImageView;
//@synthesize myScrollView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/* UIImage *myImage = [UIImage imageNamed:@"de_dust2.png"];
myImageView = [[UIImageView alloc] initWithImage:myImage];
myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 0.75;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
// [myScrollView addSubview:myImageView];*/
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.viewController setRed:1];
[self.viewController setGreen:0];
[self.viewController setBlue:0];
[self.viewController setAlpha:1];
[self.viewController checkRotation];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
我的 viewController.h
//
// ViewController.h
// drawern
//
// Created by Marin Jelica on 2012-11-21.
// Copyright (c) 2012 Marin Jelica. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController {
CGPoint lastPoint;
CGPoint moveBackTo;
CGPoint currentPoint;
CGPoint location;
NSDate *lastClick;
BOOL mouseSwiped;
UIImageView *drawImage;
UIImageView *frontImage;
}
- (IBAction)blueButton:(id)sender;
- (IBAction)greenButton:(id)sender;
- (void)checkRotation;
@property int red;
@property int green;
@property int blue;
@property int alpha;
@property int height;
@property int width;
@end
我的 viewController.m
//
// ViewController.m
// drawern
//
// Created by Marin Jelica on 2012-11-21.
// Copyright (c) 2012 Marin Jelica. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize red;
@synthesize green;
@synthesize blue;
@synthesize alpha;
@synthesize height;
@synthesize width;
- (void)viewDidLoad
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
drawImage.image = [defaults objectForKey:@"drawImageKey"];
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = self.view.frame;
[self.view addSubview:drawImage];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
width=3000;
height=3000;
// UIImage *image = [[UIImage alloc] init]
/*
UIImage *myImage = [UIImage imageNamed:@"de_dust2.png"];
myImageView = [[UIImageView alloc] initWithImage:myImage];
myScrollView.contentSize = CGSizeMake(myImageView.frame.size.width, myImageView.frame.size.height);
myScrollView.maximumZoomScale = 4.0;
myScrollView.minimumZoomScale = 0.75;
myScrollView.clipsToBounds = YES;
myScrollView.delegate = self;
// [myScrollView addSubview:myImageView];*/
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if ([touch tapCount] == 2) {
drawImage.image = nil;
}
location = [touch locationInView:touch.view];
lastClick = [NSDate date];
lastPoint = [touch locationInView:self.view];
lastPoint.y -= 0;
[super touchesBegan: touches withEvent: event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(CGSizeMake(width , height));
[drawImage.image drawInRect:CGRectMake(0, 0, width, height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, alpha);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
[drawImage setFrame:CGRectMake(0, 0, width, height)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[self.view addSubview:drawImage];
}
- (IBAction)blueButton:(id)sender {
blue=1;
red=0;
green=0;
}
- (IBAction)greenButton:(id)sender {
green=1;
blue=0;
red=0;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
[self checkRotation];
}
-(void)checkRotation{
NSLog(@"Width:%i", width);
NSLog(@"Height:%i", height);
UIInterfaceOrientation orientation = self.interfaceOrientation;
if (orientation==UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) {
// width = 3000;
// height = 3000;
[drawImage setFrame:CGRectMake(0, 0, width, height)];
// drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[self.view addSubview:drawImage];
}
if (UIInterfaceOrientationIsPortrait(orientation)) {
// width = 3000;
// height = 3000;
[drawImage setFrame:CGRectMake(0, 0, width, height)];
// drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
[self.view addSubview:drawImage];
}
}
@end
这是启动时崩溃时发生的情况的图像