I tried using the suggested code from RevMob to show a banner ad with a specific placement ID without success, tried this code:
RevMobAds *revmob = [RevMobAds revMobAds];
RevMobBanner *banner = [revmob bannerWithPlacementId:#"ID_FROM_REV_MOB"];
[banner showAd];
Tried even to add the following statement
if (IS_iPad) {
banner.frame = CGRectMake(0, 958, 768, 66);
} else if (IS_WIDESCREEN){
banner.frame = CGRectMake(0, 518, 320, 50);
} else {
banner.frame = CGRectMake(0, 430, 320, 50);
}
but no success, the only way I could be able to show banner ads was this:
[RevMobAds showBannerAdWithFrame:CGRectMake(0, 958, 768, 66) withDelegate:self];
But it didn't help to add the placement ID.
I think you need to do it as the following by using the RevMobBannwerView instead:
RevMobAds *revmob = [RevMobAds revMobAds];
RevMobBannerView *revBannerView = [revmob bannerViewWithPlacementId:#"ID_FROM_REV_MOB"];
if (IS_iPad) {
revBannerView.frame = CGRectMake(0, 958, 768, 66);
} else if (IS_WIDESCREEN){
revBannerView.frame = CGRectMake(0, 518, 320, 50);
} else {
revBannerView.frame = CGRectMake(0, 430, 320, 50);
}
[revBannerView loadAd];
[self.view addSubview:revBannerView];
[self.view bringSubviewToFront:revBannerView];
When I'm adding it(RevMob version 5.9) in my project. I do it like this:
[RevMobAds startSessionWithAppID:#"my id"];
RevMobBannerView *ad = [[RevMobAds session] bannerView]; // you must retain this object
[ad loadWithSuccessHandler:^(RevMobBannerView *banner) {
banner.frame = CGRectMake(0, 381, 320, 50);
[self.window.rootViewController.view addSubview:banner];
NSLog(#"Ad loaded");
} andLoadFailHandler:^(RevMobBannerView *banner, NSError *error) {
NSLog(#"Ad error: %#",error);
} onClickHandler:^(RevMobBannerView *banner) {
NSLog(#"Ad clicked");
}];
I am new to iOS, trying to create custom camera using AvCam. I am having trouble getting landscape orientation preview -- it rotates the view 90 degree clockwise and shows it on a half screen.
I get this message --
WARNING: -[ setOrientation:] is deprecated.
Please use AVCaptureConnection's -setVideoOrientation:
AVCaptureConnection already sets orientation, so I have no clue what am I supposed else.
I know this question was asked lots of times for previous versions of iOS (4,5), but non of those techniques/codes worked for me (iOS 6).
Original code (did not make any changes from Apple)
if ([self captureManager] == nil) {
AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
[self setCaptureManager:manager];
[manager release];
[[self captureManager] setDelegate:self];
if ([[self captureManager] setupSession]) {
// Create video preview layer and add it to the UI
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[newCaptureVideoPreviewLayer setFrame:bounds];
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
AVCaptureConnection chunk:
-(void)startRecordingWithOrientation:(AVCaptureVideoOrientation)videoOrientation; {
AVCaptureConnection *videoConnection = [AVCamUtilities connectionWithMediaType:AVMediaTypeVideo fromConnections:[[self movieFileOutput] connections]];
if ([videoConnection isVideoOrientationSupported])
[videoConnection setVideoOrientation:videoOrientation];
[[self movieFileOutput] startRecordingToOutputFileURL:[self outputFileURL] recordingDelegate:self];
}
Last time i also stumbled upon this issue. I solved this problem by doing two things
Getting the right orientation
Replace
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:AVCaptureVideoOrientationPortrait];
}
With
if ([newCaptureVideoPreviewLayer.connection isVideoOrientationSupported]) {
[newCaptureVideoPreviewLayer.connection setVideoOrientation:[UIDevice currentDevice].orientation];
}
Force the update of the video orientation during the initialization to catch video output in landscape mode by triggering
- (void)deviceOrientationDidChange manually within AVCaptureManager.m
I added it to:
- (BOOL) setupSession
{
BOOL success = NO;
...
AVCamRecorder *newRecorder = [[AVCamRecorder alloc] initWithSession:[self session] outputFileURL:self.lastOutputfileURL];
[newRecorder setDelegate:self];
[self performSelector:#selector(deviceOrientationDidChange)];
...
return success;
}
So, here's a workaround, but I am sure that there must be better solution than this. I got part of the code from this question :
iPhone App - Show AVFoundation video on landscape mode
But had to adjust frame for every orientation in order to make it work on iOS6 (and it still shows a warning):
-(void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[CATransaction begin];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeLeft;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 480, 320);
} else if (toInterfaceOrientation==UIInterfaceOrientationPortrait){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationPortrait;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 320, 480);
} else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight){
captureVideoPreviewLayer.orientation = UIInterfaceOrientationLandscapeRight;
captureVideoPreviewLayer.frame = CGRectMake(0, 0, 480, 320);
}
[CATransaction commit];
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
Has anyone integrating mobclix into a cocos2d application? I tried to add a banner of Ad by using Mobclix, but it did not appear, my code:
//In appDelegate:
[Mobclix startWithApplicationId:#"4778FFA3-DDFF-4550-BFFE-7B7AB4B5765D"];
[Mobclix start];
//In my Scene
-(void)onEnter {
adView = [MobclixAdViewiPhone_320x50 new];
adView.delegate = self; //Optional
// set position
adView.frame = CGRectMake(10, 20, 320, 50);
dView.refreshTime = 15;
// add to view
[[[CCDirector sharedDirector] openGLView] addSubview:adView];
// set refresh (automatically gets one ad when changing the property)
[adView getAd];
[super onEnter];
Anyone help me to show Adbanner on my Scene please?
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];
}
I am trying to display a modal view controller as a UIPresentationFormSheet. The view appears, but I can't seem to resize it. My XIB has the proper height & width, but it seems to get overridden when I call it like this:
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:composeTweetController animated:TRUE];
Any thoughts? I am using the iPhone SDK 3.2 beta 4
You are able to adjust the frame of a modal view after presenting it:
Tested in iOS 5.1 - 7.1
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentViewController:targetController animated:YES completion:nil];
if(floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1){
targetController.view.superview.frame = CGRectInset(targetController.view.superview.frame, 100, 50);
}else{
targetController.view.frame = CGRectInset(targetController.view.frame, 100, 50);
targetController.view.superview.backgroundColor = [UIColor clearColor];
}
Here's a method that works on iOS7 as well as iOS5 and iOS6: (arc)
-(void)presentController:(UIViewController*)controller fromRootController:(UIViewController*)rootController withSize:(CGSize)size
{
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller];
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[rootController presentModalViewController:nav animated:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
nav.view.superview.backgroundColor = [UIColor clearColor];
nav.view.bounds = CGRectMake(0, 0, size.width, size.height);
}
else
{
nav.view.superview.bounds = CGRectMake(0, 0, size.width, size.height);
}
}
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:composeTweetController animated:TRUE];
//if you want to change its size but the view will remain centerd on the screen in both portrait and landscape then:
composeTweetViewController.view.superview.bounds = CGRectMake(0, 0, 320, 480);
//or if you want to change it's position also, then:
composeTweetViewController.view.superview.frame = CGRectMake(0, 0, 320, 480);
As of iOS7 you can simply do
composeTweetController.preferredContentSize = CGSizeMake(380.0, 550.0);
Tested and works for iOS 6, using XCode 4.5
I stumbled upon my answer after reading much of the tips on here:
In the viewWillAppear:(BOOL)animated method:
[super viewWillAppear:animated];
//resize modal view
self.view.superview.bounds = CGRectMake(0, 0, 432, 680);
In the viewDidAppear:(BOOL)animated method:
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
self.view.superview.center = centerPoint;
I tried to add the centering code in the same place as the resizing code, but that did not work. For some reason, it only works after the view has appeared on the screen.
I surmise that it has something to do with the way that UIModalPresentationFormSheet works, because when I was stepping through in the LLDB debugger, I noticed that there was a variable _formSheetSize that was still {540, 620}. Go figure.
This will work with any UIModalTransitionStyle
#interface BaseDialog ()
#property(nonatomic,assign) CGRect origFrame;
#end
#implementation BaseDialog
-(void)viewDidLoad{
[super viewDidLoad];
self.origFrame=self.view.frame;
}
-(CGSize)formSheetSize{
return self.origFrame.size;
}
Following first code is how to present your model view controller
composeTweetController = [[ComposeTweet alloc] initWithNibName:#"ComposeTweet" bundle:nil];
composeTweetController.modalPresentationStyle = UIModalPresentationFormSheet;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:composeTweetController];
navigationController.delegate = self;
[self presentModalViewController:navigationController animated:YES];
And In your ComposeTweet controller class
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.view.superview.frame = CGRectMake(0, 0,500,400);
}
iOS 7
So the approach of setting the superview's frame or bounds doesn't work anymore on iOS 7 (for UIModalTransitionStyleCoverVertical). You can, however, now set the background color of the superview to clear and then change the frame of the modal view controller how you see fit.
So in iOS 7 you will want to:
present the view controller (presentation mode: UIModalPresentationFormSheet)
set view controller superview background color to clear
change frame of view controller as desired (perhaps making it smaller and then centering it in superview)
I got a full screen modal view from UIPresentationFormSheet with just this line:
modalViewController.view.superview.bounds = CGRectMake(0, 0, 1024, 748);
#bdrobert sadly your nice solution does not work anymore on iOS6 - the container keeps the original size even though the new viewcontroller is embedded with the custom size.
You probably need to use the containment API introduced in iOS5, but you need to add a dimmed background on your own, fetching all touch events for that area.
On change of orientation, this code work perfect....
settingViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:settingViewController animated:YES completion:nil];
settingViewController.view.superview.frame = CGRectMake(0, 0, 700, 700);
UIInterfaceOrientation currentOrientation = [self getDeviceOrientation];
if(currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
settingViewController.view.superview.center = centerPoint;
}
else
{
CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.height/2, [[UIScreen mainScreen] bounds].size.width/2);
settingViewController.view.superview.center = centerPoint;
}
The modern ios13 way:
use popover (formsheet and page ignore preferredContentSize)
then set or override preferredContentSize aka Ed Pilowat & Co
The view size is fixed. You will have to implement things yourself if you want something different.