placing smaato ads in different positions - iphone

I'm starting to know smaato and I'm planning to shipping it with my first published app. I used the method in the documentation
banner = [[SOMABannerView alloc] initWithDimension:kSOMAAdDimensionDefault];
[[self view] addSubview:banner];
To create the banner and then place it in the main view. It appears nice and pretty in the top. The thing is, I want it to be presented in the bottom of the screen. I know it's best for advertising to go in the top, so it drives more user attention, but for this case I just need it in the bottom. I tried making a subview with a rect and adding the banner to the subview, but it still shows up in the top. I read trough the little documentation to find nothing.
Has anybody came up with this problem before?

Never mind, for some reason it didn't work last night but it does right now. For others with this same problem, the fix was putting a low subview and loading the banner there.
UIView *vista = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 380, 50)];
[vista addSubview:banner];
[[self view] addSubview:vista];

Related

Programmatically zooming into small area of larger picture using UIScrollView

I'm trying to get my code to programmatically zoom into a small area of the larger picture. I'll add the tap code later, but right now I just want to see it work.
The zoomToRect in this code does absolutely nothing and I simply don't understand why. When I build it, the image just sits there at the 0,0 origin.
I've tried using:
setContentOffset and scrollRectToVisible and both these work fine -the image moves to the specified coordinates. But neither of these is what I want, because I need to move and zoom the image, not just move it.
But zoomToRect utterly refuses to do anything. I've read about 50 pages of examples and tutorials on this now and not a damn thing works. I'm tearing my hair out not knowing why. Clearly I'm missing some really fundamental or important point.
UIImage *myFirstImage = [UIImage imageNamed:#"manga_page.jpg"];
UIImageView *myFirstImageView = [[UIImageView alloc] initWithImage:myFirstImage];
[myFirstImageView setFrame:CGRectMake(0, 0, myFirstImage.size.width, myFirstImage.size.height)];
UIScrollView *myFirstScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[myFirstScrollView setContentSize:CGSizeMake(myFirstImage.size.width, myFirstImage.size.height)];
[myFirstScrollView addSubview:myFirstImageView];
[self.view addSubview:myFirstScrollView];
[myFirstScrollView zoomToRect:CGRectMake(300, 300, 300, 300) animated:YES];
The problem was that I hadn't defined the delegate for zooming - see viewForZoomingInScrollView (bottom of page) here:
https://developer.apple.com/library/ios/documentation/uikit/reference/uiscrollviewdelegate_protocol/Reference/UIScrollViewDelegate.html#//apple_ref/occ/intfm/UIScrollViewDelegate/viewForZoomingInScrollView
I don't have a code fragment in Objective C as I switched to the Xamarin framework. However the C# solution is as follows:
scrollView.ViewForZoomingInScrollView = delegate (UIScrollView sv) { return imageView; };
Where imageView is the UIImageView containing the image to be scrolled around.
Set the maximumZoomScale and minimumZoomScale properties for the UIScrollView.

UIPopoverController for iPhone

Does anyone know of how I would go about creating a UIPopoverController like the one found in Tweetbot form Tapbots? For months I have been trying to figure this out and gave up thinking it wasn't possible. When Tweetbot received an update with this, it made realize it is possible but I still can't seem to figure it out. Does anyone know of classes I could download that has an identical UIPopover?
Thanks
Edit: http://d.pr/LPI9
Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception.
If you need custom popOverController check this link
Custom uipopovercontroller for iPhone
TestTableViewController *vc = [[TestTableViewController alloc]initWithStyle:UITableViewStylePlain];
[self addChildViewController:vc];
[self.view addSubview:vc.view];
[self.view bringSubviewToFront:vc.view];
[vc.view setFrame:CGRectMake(20, 20, 100, 200)];
You can create a child view as uipopviewcontroller , beware not add childview on a scrollview , otherwise the scroll effect vanishes .

UIScrollView scrollRectToVisible isn't doing anything

I'm not really sure why this isn't working, hopefully you can help me find the missing piece. I have a UIScrollView with paging enabled. I'm using it for side-scrolling through a tutorial. I have a button that when tapped should scroll the user back to the beginning of the tutorial. I originally tried using the scroll view's frame as the rect to scroll to because that CGRect should represent the first page. I've tried a couple of different CGRects to no avail though.
- (IBAction) touchedButtonReturnToBeginning:(id)sender {
// I've tried several CGRect's, none of which cause the UIScrollView to move.
// CGRect beginning = self.containerScrollView.frame
// CGRect beginning = self.containerScrollView.bounds;
CGRect beginning = CGRectMake(0, 44, 1, 1);
[self.containerScrollView scrollRectToVisible:beginning animated:YES];
}
I have verified that self.containerScrollView is hooked up in my xib as well as the touchedButtonReturnToBeginning action is connected to my button. I've used my debugger to step through this method, so I have verified that it is getting called. All of the variables are appropriately set, but when I call scrollRectToVisible the scroll view just doesn't do anything.
Any ideas?
I don't know why that wouldn't work, but have you tried [self.containerScrollView setContentOffset:CGPointZero animated:YES]?
To make scrollRectToVisible works check your self.containerScrollView.contentSize. It should be big enough :)

frequent bug in UI (tabbar pushed from navigation)

I have encountered this bug several times. I have a application with a navigation controller (navbar hidden). when a button is "pressed" i want to push another view with a tabbarviewcontroller. When the new view is pushed, it's 20 pixels lower than it should (and part of the tabbar is not visible).
If I enter modal-view controller from the tabbarviewcontroller and then i dismiss it, the tabbarviewcontroller is shown properly.
I put the status bar in every view to be unspecified (thought that was the problem) and i un-checked the autoresize subviews from each view.
in your code use bounds property instead of application frame . in my it worked hope to work in case too.......:)
This sounds like it might be related to a known NIB/XIB file bug (for more information see: http://forums.bignerdranch.com/viewtopic.php?f=51&t=125)
As the linked forum topic suggests, for a workaround simply use the following:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
[[self view] setFrame:appFrame];
}
thank you for your answers. i did it somehow, playing with the tabbar's frame a bit.
[self.tabBarController.view setFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:tabBarController.view];
[self.view bringSubviewToFront:tabBarController.view];
i remember trying this a while ago and not working. now it did.
also, medling with bounds helped a bit.

View not completely covering the entire screen

Once again I've searched for about 45 minutes for an answer to this question and I thought I might have found the answer but then the situation I was reading wasn't exactly like the one I'm running into.
when I add my view it seems that it's not completely covering the window I was able to get rid of the status bar at the top but there is a section of space at the bottom that the view is not covering
alt text http://img177.imageshack.us/img177/8844/picture1zjv.png
as you can see from the screenshot there is an orange bar...it's orange because I know what it actually is under there (it's the viewController's view but everything I try I can't seem to get the added view to cover the screen.
this is the only code that's run
(void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:mainMenu];
}
Any help would be appreciated.
There are a few things that might be going wrong:
Your frame might be too short. In viewDidLoad: you can add a debug statement to check its height:
NSLog(#"Height is %f", self.view.frame.size.height);
It looks like you want that value to be 480, the full height of the screen.
Your origin might be too high. Similarly check your y offset:
NSLog(#"y origin is %f", self.view.frame.origin.y);
It looks like you want that value to be 0.
The origin of your superview might be too high. Assuming you this view only has one superview, this code will help check the absolute coordinates of your view's origin:
CGPoint absoluteOrigin = [self.view convertPoint:self.view.frame.origin
toView:self.view.superview];
NSLog(#"y origin in superview is %f", absoluteOrigin.y);
You can just tag on a few extra .superview's to find out the coordinates in terms of the prior views.
By the way, instead of just using 480 as a magic number in your code, you might want to do something like this to get the full height:
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
CGFloat screenHeight = appFrame.size.height;
The applicationFrame property takes into account whether or not the status bar is displayed.
You should post your code, but in general, you can make a UIView fill the screen as follows:
UIView *foo = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
And you can set the frame later:
foo.frame = CGRectMake(0,0,320,480);
To fill the screen, you should use a 320 x 480 Rectangle, at origin (0,0). That's what that CGRectMake function above creates.
I've had this problem before, I fixed it by just moving the view down 20 pixels...
When you use interface builder it has that nifty little "simulate status bar" or "simulate toolbar" feature but I think its kind of finnicky.
Both Andrew and Tylers answers should work though, no shame in doing things programmatically :). If you are creating the stuff in interface builder, just do Andrew's second line though, don't need to reinitialize.
Ok, well I figured it out and now I feel kind of stupid...I went back to IB and realized that the height of each view was set at 460 and not 480...you guys did give me a bunch of good information and I appreciate it all. I wish I could mark them all as answers.
Thank you again,
BWC