how to add a custom subview inside TTThumbviewController (Three20) - iphone

i am developing an iphone application which have to show images from server as thumbnail list. I have created thumbnailview using Three20 package TTThumbViewcontroller class.
Now i have to add banner view above the thumbnail view as shows in the image. Also i have to add the bottom banner view in the TTPhotoviewcontroller also.
can anyone guide me, how to add my custom banner view (UIView) along with either TTThumbviewConntroller or TTPhotoViewController to my parent view?
Edit:I had successfully added a subview for the controller which extends TTThumbViewcontroller. Now i have to add a subview above the TTPhotoViewController toolbar (as in the attached image).
thanks in advance.
Ram

The banner view is nothing different than a normal view. So you could do the same with any other view. Following is the code I use in my app (I have the same banner view at the bottom of the screen, you can adjust its position to put in above the tab bar):
- (void)viewDidLoad{
[super viewDidLoad];
//we don't want user to see the ads at the very first load.
//once, it succeeds, it will be animated up by the bannerViewDidLoadAd
adView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[adView setDelegate:self];
[self.view addSubview:adView];
self.bannerIsVisible = NO;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
adView.frame = CGRectMake(0, 346, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
adView.frame = CGRectMake(0, 480, 320, 50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (void)dealloc{
adView.delegate = nil;
[adView release];
[super dealloc];
}

Related

Cannot seem to move iAd banner to the top of the screen with this code

I have searched and searched and have done lots of trial and error on this code trying to move the ad banner to the top of the screen. It has been a week already with no progress. If anyone could help me out with this issue I would be thrilled. The code this is based off of is by the gentleman's great tutorial:
http://codewithchris.com/iad-tutorial/
Here's the code:
#interface ViewController ()
{
BOOL _bannerIsVisible;
ADBannerView *_adBanner;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
_adBanner.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!_bannerIsVisible)
{
// If banner isn't part of view hierarchy, add it
if (_adBanner.superview == nil)
{
[self.view addSubview:_adBanner];
}
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"Failed to retrieve ad");
if (_bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// Assumes the banner view is placed at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
}
#end
Change this line:
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, 320, 50)];
To this:
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, -50, 320, 50)];
(where the -50 is the height of the ad banner.) Before you were setting the ad banner's frame to the bottom of the screen using self.view.frame.size.height, whereas now the -50 moves the frame just above the screen.
Also, don't forget you'll need to reverse your CGRectOffsets' y coordinates (remove the (-) from the first and add it to the second) because the ones you have at the moment assume the frame is at the bottom of the screen.
Hope this helps!

iAd Banner not working

SO I used a tutorial to create an iAd Banner at the bottom of the screen and animate it into and out of the window, however the app is a tab based, and i do not quite know the correct offset, so you could tell me I would appreciate it, however the primary problem, is that the adBanner does not always appear, and when it does sometimes it is just a white box. Here is my code.
In my .h
#interface section3 <ADBannerViewDelegate>{
ADBannerView *adView;
BOOL bannerIsVisible;
}
#property (nonatomic, assign) BOOL bannerIsVisible;
//in the .m in the view did load
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0.0, 410.0f);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, -50.0f);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
if (self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
banner.frame = CGRectOffset(banner.frame, 0.0, 50.0f);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I am using Xcode 4.2.1
Thank you very much, any help would be appreciated :)
The tabbar is 44px high so u must add to one of the "50" 44 and make 410 to the full screen size of 3.5 inch means to 480 default. That should be the solution.

How to zoom image to fullscreen mode?

I have paging UIScrollView with images. I want to implement animated zooming of image to fullscreen on some gesture. And another animation to zoom image back to scroll view. Like in Photos app on iPad or like videos in Safari.
Of course it would not be UIImageView. It would be some wrapper class with image inside. The main question is how to present fullscreen view. Is it must be modal view or not.
Any help is appreciated.
Check on touching the image
if it is small convert into full size.
if it is large convert into small size.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (isLarge) [self makeSmall];
else [self makeFull];
}
- (void)makeFull {
[[self superview] bringSubviewToFront:self];
isLarge = YES;
CGRect largeFrame = [self superview].bounds;
original = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setFrame:largeFrame];
[internal setFrame:self.bounds];
[UIView commitAnimations];
}
- (void)makeSmall {
isLarge = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setFrame:original];
[internal setFrame:self.bounds];
[UIView commitAnimations];
}
I found a solution to this that involves both gesture recognizers and animated transitions. You remove the scrollview and add the fullscreen image. Then reverse that to return to the just the scrollview.
Use the frame of the window to determine size for the new UIImage.
The types of gesture recognizers can be adjusted to suit your needs!
-(void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapTwice:)];
tapTwice.numberOfTapsRequired = 2;
[self.imageView addGestureRecognizer:tapTwice];
}
- (void)tapOnce:(id)tapOnce {
[UIView transitionWithView:self.view
duration:0.7
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.fullScreenImage removeFromSuperview];
}
completion:nil];
}
- (void)tapTwice:(id)tapTwice {
if(self.fullScreenImage == nil){
self.fullScreenImage = [[UIImageView alloc] initWithFrame:self.view.window.frame];
UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapOnce:)];
tapOnce.numberOfTapsRequired = 1;
[tapOnce requireGestureRecognizerToFail:tapTwice];
[self.fullScreenImage addGestureRecognizer:tapOnce];
[self.fullScreenImage setUserInteractionEnabled:YES];
//self.fullScreenImage = [load your image here]
}
[UIView transitionWithView:self.view.window
duration:0.7
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.view.window addSubview:self.fullScreenImage];
}
completion:nil];
}
Download this sample for Image gallery sample code and get through it. It would definitely helps you to understand how to implement your idea.
Like below you can use for zooming the image view.
UIView * viewForScroll;
UIImageView *imgviewForScroll;
UIScrollView *scrollToRead = [[UIScrollViewalloc]initWithFrame:CGRectMake(175, 5, 300, 311)];
scrollToRead.backgroundColor = [UIColordarkGrayColor];
scrollToRead.showsHorizontalScrollIndicator = YES;
scrollToRead.delegate = self;
[scrollToRead setContentSize:CGRectMake(0, 0, 300, 400).size];
scrollToRead.maximumZoomScale = 2;
scrollToRead.minimumZoomScale = 1;
[self.view addSubview:scrollToRead];
[scrollToRead release];
viewForScroll = [[UIViewalloc]initWithFrame:CGRectMake(0,0,300,400)];
[scrollToRead addSubview:viewForScroll];
[viewForScroll release];
imgviewForScroll = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,300,400)];
imgviewForScroll.image = [UIImageimageWithContentsOfFile:[arrayComicContentobjectAtIndex:0]];
[viewForScroll addSubview:imgviewForScroll];
[imgviewForScroll release];
//=========UIScrollView Delegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return viewForScroll;
}
Like to know if you need any further clarifications

dismissModalViewController with iAds. A banner view has an ad but may be obscured

Heres my issue. I have a login screen which is shown using PresentModalViewAnimated. Once the user logins in it is dismissed.
On the login screen i have a iAd but when it is dismissed I get this error.
ADBannerView: WARNING A banner view (0x5a37df0) has an ad but may be
obscured. This message is only printed once per banner view
Also when I login then log back out, the iAd is not displayed again.
Snippets of my code
#synthesize bannerIsVisible;
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, -50);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(#"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;
if (!willLeave && shouldExecuteAction)
{
// stop all interactive processes in the app
// [video pause];
// [audio pause];
}
return shouldExecuteAction;
}
- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
// resume everything you've stopped
// [video resume];
// [audio resume];
}
- (void)viewDidLoad
{
interestingTags = [[NSSet alloc] initWithObjects: INTERESTING_TAG_NAMES2]; //set interestingTag var to define
self.userArray = [[NSMutableArray alloc] init]; //init the userArray
adView = [[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectOffset(adView.frame, 0, -50);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierPortrait];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.view addSubview:adView];
adView.delegate=self;
self.bannerIsVisible=NO;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
I think that with this you could to eliminate the error. Just removing the banner view in ViewWillDisappear:
-(void)viewWillDisappear:(BOOL)animated
{
[bannerView removeFromSuperview];
}

iAd in iPhone animates when not loaded

I have added a banner view for implementing iAd in the bottom of the screen. But when running on the simulator the banner view is slightly above the frame fixed for it. It appears as a transparent strip and is not selectable. After sometime it automatically comes to the bottom as a black strip saying Test Advertisement.
I want the banner View to stick to the bottom and not animate.
Here is my code. The adView declaration code:
adView = [[[ADBannerView alloc] initWithFrame:CGRectOffset(CGRectZero, 0, 350)] autorelease];
adView.frame = CGRectMake(0,340,320,25);
adView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifier320x50];
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
adView.tag = 111;
[self.navigationController.view addSubview:adView];
adView.delegate = self;
self.bannerIsVisible = NO;
adView.hidden = YES;
Here are the delegate methods.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if (!self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is invisible now and moved out of the screen on 50 px
banner.frame = CGRectOffset(banner.frame, 0, 50);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
// When iAd is not availale on the banner
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (self.bannerIsVisible) {
[UIView beginAnimations:#"animateAdBannerOff" context:NULL];
// banner is visible and we move it out of the screen, due to connection issue
banner.frame = CGRectOffset(banner.frame, 0, 520);
[UIView commitAnimations];
self.bannerIsVisible = NO;
}
}
I am not able to understand the problem. Kindly help.
First.
When the main view is loaded how are the objects placed in it initially? I always place them in right positions inside viewDidLoad method. So place your banner below the bottom of the main view making sure that
myBannerFrame.origin.x = 0;
myBannerFrame.origin.y = mainView.frame.size.height;
[myBanner setFrame:myBannerFrame]; // no need for animation here!
Also viewDidLoad is a good place to set your flag self.bannerIsVisible to FALSE.
Second. Do not use fixed pixel values like here
banner.frame = CGRectOffset(banner.frame, 0, 50);
instead of 50 you better put banner.frame.size.height
This will help you to avoid many errors and misalignments.