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

TwinofSian

macrumors member
Original poster
Oct 23, 2011
53
0
This is what I am trying to do:
tjAd-1.jpg


edit: see bottom post for current stage.
 
Last edited:
Do you think you can get two views with code like this

Code:
UIView* more = myView * 2; // ???

You can't do arithmetic with UIView*'s and you can't multiply a struct.

You need to look up what a struct is and look up what a CGRect is. Then it should be obvious how you can resize a frame.
 
Hey PhoneyDev, thanks for the tip.

plz see bottom of page for current stage.
 
Last edited:
So I have been reading up on CGRect, and have been trying to effectively scale a tapjoy ad so instead of encompassing 100% of the device's window, it encompasses (say) only 70%.

To that end, I have been trying to write a method within:


Code:
- (UIView*)showFeaturedAppFullScreenAd:(NSString*)adURL withFrame:(CGRect)frame
{
	UIView *fullScreenAdView = nil;
	
	[self moveViewToFront];
	
	[self.view setAlpha:1];	
	
	fullScreenAdView = [TJCFeaturedAppViewHandler showFullScreenAdWithURL:adURL withFrame:frame];
[self.view addSubview:fullScreenAdView];
	
	return fullScreenAdView;
}

In this method I added:


Code:
	fullScreenAdView.frame = CGRectMake(600, 120, [[UIScreen mainScreen]applicationFrame].size.width * 0.5f, 
[[UIScreen mainScreen] applicationFrame].size.height * 0.5f);

What I did was then replace all the other methods related to this class that called the .bounds like:


Code:
- (UIView*)showFeaturedAppFullScreenAdWithURL:(NSString*)adURL
{
	return [self showFeaturedAppFullScreenAd:adURL 
withFrame:self.view.frame]; //replaced bounds w/ frame
}

I replaced with .frame.


The code successfully compiled, but it isn't scaling everything properly. Instead this is the result:

photo2.png


I can change the * 0.7f to * 0.5f for both, I can set the origin to (80, 50) or (500, 150) it makes no difference. That is the result I get.

So now I need to figure out how to scale this. Maybe I have gone on the completely wrong track and need to change bounds instead?
 
Setting the frame is the normal way to resize and position a view. It's possible that the showFullScreenAdWithURL:frame: method is changing the frame from what you set. If you just addSubview with a UIView that you alloc/initWithFrame: does that work the way you expect? (set its background color to blueColor or something so you can see where it is)

I don't know anything about that method you're using to create the view.
 
Setting the frame is the normal way to resize and position a view. It's possible that the showFullScreenAdWithURL:frame: method is changing the frame from what you set.

I don't know anything about that method you're using to create the view.
maybe.

Here's the showFullScreenAdWithURL:frame: method


Code:
+ (UIView*)showFullScreenAdWithURL:(NSString *)adURL withFrame:(CGRect)frame
{
	//[[TJCFeaturedAppView sharedTJCFeaturedAppView] initWithFrame:frame];
	[[TJCFeaturedAppView sharedTJCFeaturedAppView] refreshWithFrame:frame];
	[[TJCFeaturedAppView sharedTJCFeaturedAppView] loadViewWithURL:adURL];
	
	[TJCViewCommons animateTJCView:[TJCFeaturedAppView sharedTJCFeaturedAppView]
	withTJCTransition:[[TJCViewCommons sharedObject] getCurrentTransitionEffect] 
	withDelay:[[TJCViewCommons sharedObject] getTransitionDelay]];
	
	return [TJCFeaturedAppView sharedTJCFeaturedAppView];
}


Another interesting thing I have found is that the additions I made to the showFeaturedAppFullScreenAd
had no effect.
As a reminder this was the addition I had made:

Code:
fullScreenAdView.frame = CGRectMake(600, 120, [[UIScreen mainScreen]bounds].size.width, 
				[[UIScreen mainScreen] bounds].size.height);

I could tell because when I commented that line of code out, and compiled the game, the ad still showed up in its usual placement like in the screenshot I posted above.

The REAL manipulating factor in this case was the method:


Code:
- (UIView*)showFeaturedAppFullScreenAdWithURL:(NSString*)adURL
{
	return [self showFeaturedAppFullScreenAd:adURL withFrame:self.view.frame]; //replaced bounds w/ frame
}

And it is this method that seems to control that awkward scaling, because the method further up the file:

Code:
-(void)showFullScreenAdWithURL:(NSString*)adURL withViewController:(UIViewController*)vController
{
	if(!vController || ![vController isKindOfClass:[UIViewController class]])
	{
		NSAssert(NO,@"View Controller provided must not be nil or some other object");
	}
	
	//[[TJCFeaturedAppView sharedTJCFeaturedAppView] initWithFrame:vController.view.bounds];
	[[TJCFeaturedAppView sharedTJCFeaturedAppView] refreshWithFrame:vController.view.frame]; //replaced bounds w/ frame
	[[TJCFeaturedAppView sharedTJCFeaturedAppView] loadViewWithURL:adURL];
	
	[vController.view addSubview:[TJCFeaturedAppView sharedTJCFeaturedAppView]];
	
	[TJCViewCommons animateTJCView:[TJCFeaturedAppView sharedTJCFeaturedAppView]
					 withTJCTransition:[[TJCViewCommons sharedObject] getCurrentTransitionEffect] 
								withDelay:[[TJCViewCommons sharedObject] getTransitionDelay]];
	
}

Still kept the .frame at the end while I changed the other method just for isolated testing, and now the ad is in its normal 100% view position.

So it seems I haven't gone deep enough into the dev code to figure this mystery out.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.