How to place UILabel on top of Chartboost Interstitial? - ios

How can i place a UIView on top of the Chartboost ad?
I tried everything. I am using the Chartboost delegate to know when an ad is displayed and then I add the UILabel but it will just get dimmed out by the Chartboost ad.
I even tried the method [self.view bringSubviewToFront:label]; but it did not work.
Anyone knows a workaround so I can display this label without it getting dimmed out by the Chartboost interstitial.
This is the code I use for the ad (The timer was just for testing):
-(BOOL)shouldDisplayInterstitial:(NSString *)location {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, -150 /2, 500, 300)];
label.textColor = [UIColor whiteColor];
label.text = #"Tap ad to get a boost";
label.font = [UIFont fontWithName:#"AvenirNext-DemiBold" size:32.6];
label.alpha = 1;
[self runAction:[SKAction waitForDuration:5] completion:^{
self.view.window.rootViewController.view = label;
}];
return YES; }

While this may be possible, it's viewed as artificially inflating (or incentivizing) clicks. These types of things are scanned for & regularly shut down.
Instead, use a number of interstitial locations in your app. Test which locations work best & at what frequency and focus your efforts there.
Full disclosure: I work at Chartboost.

Related

How to have User Input in a SKScene

I'm trying to ask the user to input their name in a SKScene but whenever I add a subview it messes up the SKScene and it starts to replay the music and doesnt add the new SKScene that I have the textfield in. Here is my attempt.
-(void)didMoveToView:(SKView *)view{
self.backgroundColor = [SKColor lightGrayColor]; // NOTE: temporary background color se
UILabel *nameField = [[UILabel alloc] initWithFrame:CGRectMake(200, 200, 300, 100)];
[self.view addSubview:nameField];
//[self createMenuTxt];
[self SetBrickBackground];
}
EDIT: I found a related post:
Adding UITextView to a scene in SpriteKit
Which says that the reason is because the skScene is being presented everytime I add a UITextview. He said to use a guard: if(self.view.scene == nil){}, however, I'm getting that scene is not a property of UIView. Am I missing something?
In this case self is the view. So in effect you are saying self.self which obviously does not work.
Change the line [self.view addSubview:nameField]; to this [view addSubview:nameField];

Come back to app from an other app

Hello,
When we are phoning with us iphone and you left the call view to come back at springboard, we can come back to the call view with the status bar. (This picture can better explain : http://what-when-how.com/wp-content/uploads/2011/08/tmpB178_thumb.jpg)
Or, in the Facebook app when you go to the messenger Facebook app (not same app) we can touch status bar to comme back Facebook App too.
I would like to know if it's possible to make it in my app ? And if it's possible, how I will proceed ? (Edit: I want co come back in my app from another app such Youtube.)
Thanks
Once you become familiar with how to open another app within your current app form following link:
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
You can simply create a view that has tap gesture and use it as a button
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
UIView *tapToReturnButton = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)];
tapToReturnButton.backgroundColor = [UIColor blueColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(tapToReturnButtonClicked)];
[tap setNumberOfTouchesRequired:1];
[tapToReturnButton addGestureRecognizer:tap];
UILabel *tapToReturnLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, 20)];
tapToReturnLabel.text = #"Tap to return";
tapToReturnLabel.textColor = [UIColor whiteColor];
tapToReturnLabel.textAlignment = NSTextAlignmentCenter;
tapToReturnLabel.font = [UIFont fontWithName:#"ArialMT"
size:14];
[tapToReturnButton addSubview:tapToReturnLabel];
[self.view addSubview:tapToReturnButton];
}
- (void)tapToReturnButtonClicked
{
NSLog(#"Now you add your code that opens another app(URL) here");
}
Edited:
After I posted the code above I kind of realized that there will be no tap gesture on the status bar even though other bottom part (20 pixel) of tapToReturnButton has a click gesture. After I did some research, I think following link has the better solution on click gesture. I will probably use tapToReturnButton as placeholder to let users know where to touch though and remove UITapGestureRecognizer *tap.
How to detect touches in status bar
Again, I think there is multiple way to achieve your need but those links above will give you good starting point.
URL schemes will allow you to launch an app from an another app.
Check the following links for more info:
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW18
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50
here are some system supported URL schemes
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007899

Cannot make programmatically created UITextField editable (iOS)

I created a UITextField programatically, (I do not use storyboard) and added it as a subview to ViewController with this code:
#interface ViewController ()
#property (nonatomic, strong) UITextField *searchLocationBar;
#end
...
#synthesize searchLocationBar;
...
self.searchLocationBar = [[UITextField alloc] init];
self.searchLocationBar.frame = CGRectMake(0.0f, 0.0f, 320.0f, 40.0f);
self.searchLocationBar.delegate = self;
self.searchLocationBar.borderStyle = UITextBorderStyleRoundedRect;
self.searchLocationBar.placeholder = #"a temporary placeholder";
self.searchLocationBar.userInteractionEnabled = YES;
self.searchLocationBar.clearButtonMode = UITextFieldViewModeAlways;
[self.view addSubview:self.searchLocationBar];
However, I cannot enter any text - nothing happens, when I tap on a textfield. It's not overlapped by any other view.
I've checked UITextfield not editable-iphone but no effect
I'm newbie and totally sure I simply miss something - please advice.
Thanks!
EDIT:
One more thing: I have a Google Maps GMSMapView assigned to self.view as
self.view = mapView_; as written in Google API documentation.
After some tests I found that with this declaration all controls work perfectly, but not textfields. I would prefer not to move a map view to any subview as I will need to rewrite lots of things.
Can someone please add any suggestions?
you forget add:
[self.view bringSubviewToFront:self.searchLocationBar];
In Xcode 5 your code should work.Better you check your Xcode version.May be the problem with your code with Xcode versions.You can try by following way.
UITextField *lastName = [[[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
[self.view addSubview:lastName];
lastName.placeholder = #"Enter your last name here"; //for place holder
lastName.textAlignment = UITextAlignmentLeft; //for text Alignment
lastName.font = [UIFont fontWithName:#"MarkerFelt-Thin" size:14.0]; // text font
lastName.adjustsFontSizeToFitWidth = YES; //adjust the font size to fit width.
lastName.textColor = [UIColor greenColor]; //text color
lastName.keyboardType = UIKeyboardTypeAlphabet; //keyboard type of ur choice
lastName.returnKeyType = UIReturnKeyDone; //returnKey type for keyboard
lastName.clearButtonMode = UITextFieldViewModeWhileEditing;//for clear button on right side
lastName.delegate = self; //use this when ur using Delegate methods of UITextField
There are lot other attributes available but these are few which we use it frequently.if u wanna know about more attributes and how to use them refer to the following link.
You can also make property for UITextField.Either way should work fine in Xcode.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextField_Class/Reference/UITextField.html

dim AND lock the background when using UIActionSheet on iPad

I have researched this question for a few hours, sounds pretty simple to me but haven't been able to find a viable solution. I have an iPad application where I'm using a UIActionSheet to confirm a delete. I'm adding a label to increase the font size. Everything looks and works great. I also have a requirement to dim and lock the background while the Action Sheet is visible. I can dim but cannot see how to lock the background so that the user must make a selection on the Action Sheet to dismiss it. I have tried setting UserInteractionEnabled but it doesn't work. Any Ideas?
// dim the background
UIView *dimViewDelete = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
dimViewDelete.backgroundColor = [UIColor blackColor];
dimViewDelete.alpha = 0.3f;
dimViewDelete.tag = 2222;
[self.view addSubview:dimViewDelete];
if ([self.listArray count] > 0)
{
// create Action Sheet
UIActionSheet * action = [[UIActionSheet alloc]
initWithTitle:#" "
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Delete"
otherButtonTitles:nil];
[action addButtonWithTitle:#"Cancel"];
[action setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[action showInView:self.view];
// change the font size of the title
CGRect oldFrame = [(UILabel*)[[action subviews] objectAtIndex:0] frame];
UILabel *addTitle = [[UILabel alloc] initWithFrame:oldFrame];
addTitle.font = [UIFont boldSystemFontOfSize:22];
addTitle.textAlignment = UITextAlignmentCenter;
addTitle.backgroundColor = [UIColor clearColor];
addTitle.textColor = [UIColor whiteColor];
addTitle.text = #"Are You Sure?";
[addTitle sizeToFit];
addTitle.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y,
oldFrame.size.width, addTitle.frame.size.height);
[action addSubview:addTitle];
}
Your best option is to implement your own custom action sheet-like control.
You need a simple view controller that has the two buttons and a label (for the title). Show the view controller in a popover. Make the view controller modal so it can only be dismissed by tapping one of the buttons. This also makes the background appear locked.
If you really need to dim the background as well, just before displaying the popover, add a screen sized UIView to the main window. Set this view's background to [UIColor whiteColor:0 alpha:0.7]. Adjust the alpha as needed to get the right dimming effect. You can even animate the alpha of the view so it fades in and out as needed.

iOS app gets completely misaligned when switching from 5 to 4.3 in simulator

I'm working on an app that is ideally targeted all the way down to iOS 3.2. Still, I am developing it on Lion and with the latest 5 sdk. As far as I know, I am not using any sdk 5 specific features. But:
on any devices with iOS 5 or the simulator (set to v.5), the app works just fine.
on any devices with iOS 4.3 or below (and the same goes for the simulator set to v. 4.3), several things that have to do with view frames get misaligned.
For instance, here's 2 examples:
An activity indicator inside an alert view. Here's the code:
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:fileRequest delegate:self];
if(urlConnection)
{
uistatusDialog = [[UIAlertView alloc] initWithTitle:(description ? NSLocalizedString(description, nil) : NSLocalizedString(#"Downloading", nil))
message:nil
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[indicator startAnimating];
[uistatusDialog addSubview: indicator];
[uistatusDialog show];
[indicator release];
And here are screenshots for both simulators:iOS 5: correct
iOS 4.3: misaligned
Similar things are happening with labels for which I set frames through [UILabel alloc]initWithFrame:CGRectMake(...].
This code, for instance:
UITableViewCell * cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:reuseIndentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
UILabel* mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(70, 0, 0, 20)] autorelease];
mainLabel.font = [UIFont boldSystemFontOfSize:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 18 : 12)];
mainLabel.textAlignment = UITextAlignmentLeft;
mainLabel.textColor = [UIColor blackColor];
mainLabel.backgroundColor = [UIColor clearColor];
mainLabel.autoresizingMask = (UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin);
//mainLabel.adjustsFontSizeToFitWidth = YES;
mainLabel.tag = MAINLABEL_TAG;
Aligns just fine in iOS5, both for the simulators and devices. But in 4.3 it doesn't.
I can only think that the local coordinate frame changed from one SDK to the next?
Any help is greatly appreciated!
EDIT: Just to pull it off for now, I did end up replacing all instances of CGRectMake(x,y,w,h) with something along the lines of (assuming x,y,w,h are the ones I would have used for CGRectMake):
CGrect refFrame = superview.frame;
refFrame.origin.x += x;
refFrame.origin.y += y;
refFrame.size.w = w;
refFrame.size.h = h;
theObjInQuestion.frame = refFrame;
So essentially, looks like a different frame of reference is being used between SDK 5 and 4.3 at least...
I had a similar issue with one UIImageView in our app being displaced downwards about 100pts on screen, appearing to be displaced by other content that should have been floating on top of the UIImageView (though that may have been a coincidence).
The 'solution' I found in our case was to disable auto-sizing for the top positioning attribute for the UIImageView in IB, by clicking on the red I in the Autosizing display on the Size Inspector in Interface Builder. I call this a 'solution' rather than a solution because it remains unclear to me why this was a problem at all, and why this only occurred for this one view and only in iOS 5.
I also found that repositioning this view up, or down, prevented it from being displaced. It was only when it was aligned with the top edge of its parent view that the issue occurred.
My conclusion was it was probably a bug in iOS 5, rather than a new intended or more strict behavior, but I remain uncertain.
There are some major differences between 4 and 5, though I've only begun to figure them out. Something has changed in the coordinate systems, but precisely what I don't know.
I kinda suspect that the best/safest thing to do is to have two entirely different paths for calculating layout, until someone can figure out all of the "gotchas". That way the two versions can be "tuned" separately.

Resources