Resizing an Instance of UIView* (HELP please!)

Discussion in 'iOS Programming' started by TwinofSian, Jan 8, 2012.

  1. TwinofSian, Jan 8, 2012
    Last edited: Jan 9, 2012

    TwinofSian macrumors member

    Joined:
    Oct 23, 2011
    #1
    This is what I am trying to do:
    [​IMG]

    edit: see bottom post for current stage.
     
  2. TwinofSian, Jan 8, 2012
    Last edited: Jan 9, 2012

    TwinofSian thread starter macrumors member

    Joined:
    Oct 23, 2011
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    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.
     
  4. TwinofSian, Jan 9, 2012
    Last edited: Jan 9, 2012

    TwinofSian thread starter macrumors member

    Joined:
    Oct 23, 2011
    #4
    Hey PhoneyDev, thanks for the tip.

    plz see bottom of page for current stage.
     
  5. TwinofSian, Jan 9, 2012
    Last edited: Jan 9, 2012

    TwinofSian thread starter macrumors member

    Joined:
    Oct 23, 2011
  6. TwinofSian thread starter macrumors member

    Joined:
    Oct 23, 2011
    #6
    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:

    [​IMG]

    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?
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #7
    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.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Are you sure your agreement with TapJoy allows you to scale down the screen size of their ads?
     
  9. TwinofSian, Jan 10, 2012
    Last edited: Jan 11, 2012

    TwinofSian thread starter macrumors member

    Joined:
    Oct 23, 2011
    #9
    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.
     

Share This Page