Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-25-2011, 04:24 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Fort Lauderdale, Florida
Posts: 67
Ins3rtNam3H3r3 is an unknown quantity at this point
Angry Admob Ad Causing Weird Problems on Device

I'm reposting this in advanced as no one was able to answer my question in the regular forum.

In my app I am doing some custom drawing in the touchesMoved method. The code to do this works, as I've tested it on the simulator. The problem is that I have an admob ad on the same view which seems to be preventing the image view that the drawing is being displayed on from updating until touchesEnded, but only on the device. I know the code is still being executed though as log statements still output, and I'm pretty sure that it is the ad causing the problems as when I turn of internet to prevent the ad from loading, everything works perfectly.
I've spent all day trying to figure out why this is happening and its been infuriating having to spend so much time on it. If anyone knows what may be causing this it would be very helpful.

Here's simple code that reproduces the problem:

Note that this only happens on the device, NOT in the
simulator.

.h
Code:
#import <UIKit/UIKit.h> 
#import "GADBannerView.h" 
@interface admobProblemsViewController : UIViewController 
{ 
    UIImageView *imageView; 
    UIImage *backgroundImage; 
    UIImage *drawImage; 
    CGPoint lastPoint; 
    GADBannerView *banner; 
} 

@property (retain, nonatomic) UIImageView *imageView; 
@property (retain, nonatomic) UIImage *backgroundImage; 
@property (retain, nonatomic) UIImage *drawImage; 
- (UIImage *)overLayImage:(UIImage *)image1 onImage:(UIImage 
*)image2; 
@end
.m
Code:
 
#import "admobProblemsViewController.h"
#import "GADBannerView.h"

@implementation admobProblemsViewController
@synthesize imageView;
@synthesize backgroundImage;
@synthesize drawImage;


- (void)viewDidLoad
{
    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 410)];
    drawImage = [[UIImage alloc] init];
    
    backgroundImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"background" ofType:@"jpg"]];
    
    [imageView setImage:backgroundImage];
    [self.view addSubview:imageView];
    
    
    banner = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0, 
                                                             self.view.frame.size.height-GAD_SIZE_320x50.height, 
                                                             GAD_SIZE_320x50.width, 
                                                             GAD_SIZE_320x50.height)];
    banner.adUnitID = @"a14d989945465d2";
    banner.rootViewController = self;
    [self.view addSubview:banner];
    [banner loadRequest:[GADRequest request]];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    
    if([touch locationInView:self.view].y>=0 && [touch locationInView:self.view].y<=410)
        lastPoint = [touch locationInView:imageView];
    
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    
    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    
    
    if(currentPoint.y>=0 && currentPoint.y<=410)
    {
                
        UIGraphicsBeginImageContext(imageView.frame.size);
                     
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 1.0, 1.0);
            
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 25);
        
        
        CGContextBeginPath(UIGraphicsGetCurrentContext());
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());                
        
                
        UIImage *temp = [[UIImage alloc] initWithCGImage:[self overLayImage:UIGraphicsGetImageFromCurrentImageContext() onImage:drawImage].CGImage];
        
        UIGraphicsEndImageContext();
        
        [drawImage release];
        drawImage = [[UIImage alloc] initWithCGImage:temp.CGImage];
        
        [temp release];
        
        [imageView setImage:[self overLayImage:drawImage onImage:backgroundImage]];
        
        
        lastPoint = currentPoint;
    }

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UIGraphicsBeginImageContext(imageView.frame.size);
    
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);

    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 1.0, 1.0, 1.0);
    
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 25);
    
    
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());      
    
        
    UIImage *temp = [[UIImage alloc] initWithCGImage:[self overLayImage:UIGraphicsGetImageFromCurrentImageContext() onImage:drawImage].CGImage];
    
    UIGraphicsEndImageContext();
    
    [drawImage release];
    drawImage = [[UIImage alloc] initWithCGImage:temp.CGImage];
    
    [temp release];
    
    [imageView setImage:[self overLayImage:drawImage onImage:backgroundImage]];

}

- (UIImage *)overLayImage:(UIImage *)image1 onImage:(UIImage *)image2
{
    UIGraphicsBeginImageContext(image1.size);
    [image2 drawAtPoint:CGPointZero];
    [image1 drawAtPoint:CGPointZero];
    
    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return result;
}


- (void)dealloc
{
    [imageView release];
    [backgroundImage release];
    [drawImage release];
    [super dealloc];
}


@end
__________________


FREE 3D Photo Maker
Ins3rtNam3H3r3 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 383
17 members and 366 guests
Absentia, AyClass, bignoggins, Diligent, dre, givensur, hussain1982, jbro, jPuzzle, momolgtm, Newbie123, Paul10, revg, skog, taylor202, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 04:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0