Gold Challenge Questions


#1

I got my gold challenge to work but there are 2 things I am having trouble with:

  1. I get an warning “Local declaration of ‘logoview’ hides instance variable” as indicated in my code below. I know this is a rookie mistake but can’t make it seem to go away without jacking up my program to the point it doesn’t work.
#import "HypnosisterAppDelegate.h"
#import "HypnosisView.h"
#import "BNRLogo.h"

@implementation HypnosisterAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    
    [[UIApplication sharedApplication]setStatusBarHidden:YES
                                           withAnimation:UIStatusBarAnimationFade];
    
    
    CGRect screenRect = [[self window] bounds];
    
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:screenRect];
    
    [scrollView setMinimumZoomScale:1.0];
    [scrollView setMaximumZoomScale:5.0];
    
    [scrollView setDelegate:self];
    
    [[self window] addSubview:scrollView];

    
    CGRect bigRect = screenRect;
  
    
    view = [[HypnosisView alloc] initWithFrame:screenRect];
    
     
    [scrollView addSubview:view];
    
   
    [scrollView setContentSize:bigRect.size];
    
    BOOL success = [view becomeFirstResponder];
    if (success) {
        NSLog(@"HypnosisView became the first responder");
    } else {
        NSLog(@"Could not become first responder");
    }
    
    //  Gold start
    
    CGRect logorect = CGRectMake(4, 4, 100, 100);
    BNRLogo *logoview = [[BNRLogo alloc] initWithFrame];
    [view addSubview];
    
    // End Gold
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return view;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
  
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
  
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
 
}

- (void)applicationWillTerminate:(UIApplication *)application
{
   
}

@end
  1. My shadow appears within my circle logo, I want it to appear below as if the logo were floating above the screen, is there a way to do this?

    -John

#2

Do you have an instance variable or property named the same in HypnosisterAppDelegate?

If so, then why are you declaring a local one?

...
    //  Gold start
    
    CGRect logorect = CGRectMake(4, 4, 100, 100);
    BNRLogo *logoview = [[BNRLogo alloc] initWithFrame];
    [view addSubview];
    
    // End Gold
...

#3

:smiley: Hi [color=#000080][size=90]jkdorman[/size][/color]! It happens, [color=#008040][size=90]Core Graphics[/size][/color] and [color=#008040][size=90]UIKit[/size][/color] are both confusing at times.

[size=90]It seems as though you might be overriding your instance variable with a local variable.

In [color=#008040]HypnosisterAppDelegate[/color] instead of:

BNRLogo *logoview = [[BNRLogo alloc] initWithFrame];try:

[/size]

[size=90]When working with [color=#008040]Core Graphics[/color] (i.e. the [color=#008040]drawRect[/color] method) it’s best to visualize additions to the context as layers of paint onto a canvas. You generally want to add the background before adding the foreground. When [color=#008040]Quartz[/color], the engine behind [color=#008040]Core Graphics[/color], is tasked with creating a shadow it essentially takes the silhouette of the last drawing added to the context, offsets, blurs and fills it using the arguments applied to the shadow state. The Order of Drawing Instructions is Important!

ex. You create a circular path then [color=#008040]CGContextStrokePath[/color] it. [color=#008040]Quartz[/color] would create a silhouette of that drawing, a stroked circle with a hollow center, and use that to create a shadow.

[color=#666]note: The gold challenge requires clipping which could prevent a shadow from being displayed if drawing instructions aren’t ordered properly.[/color]
[/size]