Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

EducationApp

macrumors newbie
Original poster
Aug 17, 2011
18
0
So I have all the IBOutlet UIButtons on the screen upon startup, but when I try to hide them, it doesn't work.
Here is the code (.h)
Code:
#import <UIKit/UIKit.h>

@interface ExplainMe_ViewController : UIViewController {
    UIImageView *drawImage;
	int mouseMoved;
	BOOL mouseSwiped;
	CGPoint lastPoint;
    
    IBOutlet UILabel *colorlabel;
    IBOutlet UILabel *drawinglabel;
    IBOutlet UILabel *textlabel;
    
    IBOutlet UIButton *colormenu;
    IBOutlet UIButton *redbutton;
    IBOutlet UIButton *bluebutton;
    IBOutlet UIButton *greenbutton;
    IBOutlet UIButton *orangebutton;
    IBOutlet UIButton *yellowbutton;
    IBOutlet UIButton *purplebutton;
    IBOutlet UIButton *greybutton;
    IBOutlet UIButton *blackbutton;
    IBOutlet UIButton *pinkbutton;
    IBOutlet UIButton *closebutton;
}

@property (nonatomic, retain) IBOutlet UILabel *colorText;
@property (nonatomic, retain) IBOutlet UILabel *drawingText;
@property (nonatomic, retain) IBOutlet UILabel *textText;


-(IBAction)colormenuhide;


-(IBAction)colormenuappear;


@end

And the .m
Code:
#import "ExplainMe_ViewController.h"

@implementation ExplainMe_ViewController
@synthesize colorText;
@synthesize drawingText;
@synthesize textText;


-(IBAction)colormenuhide {
    colormenu.hidden = YES;
    redbutton.hidden = YES;
    bluebutton.hidden = YES;
    greenbutton.hidden = YES;
    orangebutton.hidden = YES;
    yellowbutton.hidden = YES;
    purplebutton.hidden = YES;
    greybutton.hidden = YES;
    blackbutton.hidden = YES;
    pinkbutton.hidden = YES;
    
}

-(IBAction)colormenuappear {
    colormenu.hidden = NO;
    redbutton.hidden = NO;
    bluebutton.hidden = NO;
    greenbutton.hidden = NO;
    orangebutton.hidden = NO;
    yellowbutton.hidden = NO;
    purplebutton.hidden = NO;
    greybutton.hidden = NO;
    blackbutton.hidden = NO;
    pinkbutton.hidden =NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
	drawImage = [[UIImageView alloc] initWithImage:nil];
	drawImage.frame = self.view.frame;
	[self.view addSubview:drawImage];
	mouseMoved = 0;
    {
        
        [colorlabel setFont:[UIFont fontWithName:@"Speedline.ttf" size:24]];
        
        [super viewDidLoad];
        colorText.text = @"Color";
        
    } 
    {
        
        [drawinglabel setFont:[UIFont fontWithName:@"Speedline.ttf" size:24]];
        
        [super viewDidLoad];
        drawingText.text = @"Drawing";
        
    } 
    {
        
        [textlabel setFont:[UIFont fontWithName:@"Speedline.ttf" size:24]];
        
        [super viewDidLoad];
        textText.text = @"Text";
        
    } 
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
	
	mouseSwiped = NO;
	UITouch *touch = [touches anyObject];
	
	if ([touch tapCount] == 5) {
		drawImage.image = nil;
		return;
	}
	
	lastPoint = [touch locationInView:self.view];
	lastPoint.y -= 20;
	
}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	mouseSwiped = YES;
	UITouch *touch = [touches anyObject];	
	CGPoint currentPoint = [touch locationInView:self.view];
	currentPoint.y -= 20; // only for 'kCGLineCapRound'
	UIGraphicsBeginImageContext(self.view.frame.size);
	//Albert Renshaw - Apps4Life
	[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
	CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
	CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size
	CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0); //values for R, G, B, and Alpha
	CGContextBeginPath(UIGraphicsGetCurrentContext());
	CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
	CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
	CGContextStrokePath(UIGraphicsGetCurrentContext());
	drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	
	lastPoint = currentPoint;
	
	mouseMoved++;
	
	if (mouseMoved == 10) {
		mouseMoved = 0;
	}
	
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
	
	UITouch *touch = [touches anyObject];
	
	if ([touch tapCount] == 5) {
		drawImage.image = nil;
		return;
	}
	if(!mouseSwiped) {
		//if color == green
		UIGraphicsBeginImageContext(self.view.frame.size);
		[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)];
		CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound
		CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
		CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
		CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
		CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
		CGContextStrokePath(UIGraphicsGetCurrentContext());
		CGContextFlush(UIGraphicsGetCurrentContext());
		drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
		UIGraphicsEndImageContext();
	}
}


- (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.
}

#pragma mark - View lifecycle

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
}
*/

- (void)viewDidUnload
{


    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
 
Are you 100% sure that all of your IBOutlet buttons and IBAction methods are wired appropriately in Interface Builder?
 
Also to make code a little bit cleaner, create a fully transparant view. add all buttons on there in IB, lay them out correctly, create one IBOutlet to that, and just set that to hide, saves you 300 lines of code or something ;)
GOod you found it out.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.