How do I remove empty space created by canDisplayAdBanner? - ios

I added iAd to my application using self.canDisplayBannerAds. The application uses UITabBarController and that seems to be causing a problem. See the "empty" (gray) space in the screenshot below.
The UITextView has the following constraints:
And the program is very simple:
#import <iAd/iAd.h>
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.canDisplayBannerAds = YES;
}
#end
This simple program, with the canDisplayBannerAds commented out (or set to NO) doesn't have a gray rectangle at all. But with ads I can't seem to get rid of that "empty" (gray) rectangle. Does anyone have a suggestion to resolve this issue?
Demo project on github.

Just make your ViewController's TabBar to Opaque and your problem will be resolved.

Related

XCode IBAction and IBOutlets errors

I'm having a bit trouble with my app and its really bothering me I was wondering if anyone could help me with IBOulets actions.
I only see action and nothing else, it won't let me change it.
any way to fix this issue. Thanks for any help
If you drag your outlet between the #implementation UIViewControllerName and the #end (bottom section of the .m file) you create a IBAction (For example for button clicks)
If you drag your outlet between the #interface UIViewControllerName() and the #end before the #implementation, you create a IBOutlet. You can create it in the .h file and in the .m file. If there is no #interface in the .m file, you can create it. Add the following above the #implementation UIViewControllerName:
#interface UIViewControllerName ()
// HERE YOU CAN DRAG YOUR IBOutlets
#end
// Here begins the viewcontrollers implementation
#implementation UIViewControllerName
- (void) viewDidLoad {
..... etc. etc..

Button and label are not shown in the iOS app using Xcode

I am trying to write a hello world app on Xcode but I have two errors
The first error message is DTAssetProviderService could not start DTXConnection with Simulator 'iPhone 5'. Check the system log for errors. but I still can run the app but when I run the app on simulatior it does not show the button and label I put in the app. It shows just a screen of the app. Here is my codes in the app for ViewController.h and ViewController.m
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UILabel *hellolabel;
}
- (IBAction)button1:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#implementation ViewController
-(IBAction)button1:(id)sender {
hellolabel.text = #"hello world";
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[ super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And here is my main.storyboard interface
enter image description here
put your button and label in top - left side in your storyboard interface builder for now and you can see it on simulator.
It is because of different screen sizes, size classes and autolayout.
You should learn autolayout, after you can set constraints to your components and this kind of problem will not be faced.
The issue is probably in your main.storyboard, which you haven't linked below. More than likely, as others have said, you've mucked up your constraints.
On your main.storyboard delete any constraints and move all your buttons to the left most side. Also make sure that your width and height read wAny hAny, as that is the best to use for any screen.

UIProgressView Keeps Resetting to 0.0

I've got a UIProgressView in my Storyboard hooked up to my code. I'm trying to set the progress to something non-zero.
Here's an example of my code that I've placed in viewDidLoad.
[self.progressBar setProgress:(float)someValueBetween0.1and1.0 animated:NO];
However, what's happening is that the progress bar will be at the value that I set, and then quickly animate down to 0.0. For instance, if I set progress to 0.5, the bar will be filled half way when the view loads and then animate down to 0.0.
I've tried using
self.progressBar.progress = (float)someValueBetween0.1and1.0;
That hasn't worked either.
I'm not modifying the progress bar's progress via code anywhere else. I've tried Googling, reading the UIProgressView Class Reference, and searching Stack Overflow without any success :/
Edit: Created a new project with nothing more than a UIProgressView just to be sure it's not something else in my code. Still not working.
#import "ViewController.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIProgressView *testProgressView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.testProgressView setProgress:1.0 animated:NO];
}
This is a bug in Xcode Version 7.0 beta (7A120f).
I've confirmed it in both Objective C and Swift.
It only occurs in the beta version, the same source executes correctly in Xcode 6.
Very strange bug.

When adding UIView instantiated with an .xib to the Storyboard buttons don't work and background color can't be changed

I am working on an iOS project and wanted to include a UIView that is reused on multiple screens in the application (appearing at the bottom of different UIViews). I am using a storyboard for the UI work so far but created an .xib file to be used by the reusable view (playerView in code below).
The view gets added but the button I have added to the View is unresponsive, also my background color cannot be changed on the view. I have tried to set background color programmatically and in the .xib with no luck. Very weird symptoms and I tried to instantiate the view from #5 of this article and probably did something wrong. I dont fully understand everything in the article which makes me nervous - for instance my showSubclassedView method returns IBAction but I just call the function name in code and dont use a button (I did hook up the buttons in the view as the article described though).
Here is the code:
EventViewController.m (where I trry and add PlayerView)
#import "EventViewController.h"
#import "PlayerView.h"
#interface EventViewController ()
-(IBAction)showSubclassedView;
#end
#implementation EventViewController
-(IBAction)showSubclassedView
{
[PlayerView presentInViewController:self];
}
PlayerView.h (.h for reusable view)
#import <UIKit/UIKit.h>
#import "Utils.h"
#class PlayerView;
#protocol PlayerViewDelegate
-(void)playerViewTouchedUp:(PlayerView*) playerView;
-(void)playerViewDidDismiss:(PlayerView*) playerView;
#end
#interface PlayerView : UIView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate>*) playerView;
-(IBAction)viewTouchedUp;
-(IBAction)dismiss;
#end
PlayerView.m (.m for reusable view)
#import "PlayerView.h"
#interface PlayerViewOwner : NSObject
#property(nonatomic,weak) IBOutlet PlayerView *playerView;
#end
#implementation PlayerViewOwner
#end
#interface PlayerView ()
#property (nonatomic, weak) UIViewController <PlayerViewDelegate> *delegateViewController;
#end
#implementation PlayerView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate> *)viewController
{
PlayerViewOwner *owner = [PlayerViewOwner new];
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:owner options:nil];
owner.playerView.delegateViewController = viewController;
[viewController.view addSubview:owner.playerView];
}
-(IBAction)viewTouchedUp
{
//forward to delegate
NSLog(#"you clicked a button");
[self.delegateViewController playerViewTouchedUp:self];
}
-(IBAction)dismiss
{
[self removeFromSuperview];
// Forward to delegate
[self.delegateViewController playerViewDidDismiss:self];
}
#end
PlayerView.xib has a UIbutton on it that connects it to viewTouchedUp method in PLayerView.m
Is there anything I did wrong in the code above? Is this the best way to do a reusable view to display on other views?
Thank you!
Here's a workaround I found after not being able to solve this.
New implementation is from this article
I reverted my changes from my initial question and implemented this. It lacks the nice protocol separation for talking back and forth and I might need something like this later but I think now I can still implement a protocol to solve this.
At least with this solution I have usable items in my view and a background that changes!

Handling touches within UIScrollview

I have a view that contains a UIScrollView. The UIScrollView contains an UIImageView (only one for now but there will be more latter). I want to be able to drag the UIImageView out of the UIScrollView and into the superview.
I have reviewed every similar question and example I can find online and still cant get my head around how this works.
At first I couldn't get touches to register all whithin the scrollview. After a lot of searching I have found a way to get touchesbegan to register as follows:
First I created a new view based project and in the auto-created "ViewController.h"
I created an IBOutlet named slider.
Then in the auto-created "ViewController.m" I created the UIScrollview.
In IB I added a UIScrollView to the storyboard then connected it to the "slider" IBOutlet.
Next I added class file to the projects. This new class is a subclass os UIImageView. I named this class "DragableImage" In the
Then in IB I dropped an image into the UIScrollview clicked on it and changed the class to "DragableImage"
In the DragableImage.m I voided touches began and simply told it to become hidden if clicked.
This works and the touch registers and makes the image disappear but how do I now add the new image to the main view and have it follow my finger?
This is what I have in the way of code:
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIScrollView *slider;
}
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[slider setScrollEnabled:YES];
[slider setContentSize:CGSizeMake(306, 1560)];
[slider setShowsVerticalScrollIndicator:NO];
slider.canCancelContentTouches = NO;
slider.delaysContentTouches = NO;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#end
DragableImage.h
#import <UIKit/UIKit.h>
#interface DragableImage : UIImageView
#end
DragableImage.m
#implementation DragableImage
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.hidden = YES;
}
#end
How to make this work?
There is one obvious problem that can arise here. Namely, how to tell the difference between dragging to scroll and dragging an image. The way I would handle this is to setup a tap and hold gesture recognizer (http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html).
Once you detect a hold you could set it up so that further touches/gestures get routed to you drag and drop code. You can find a nice tutorial for that here:
http://www.ancientprogramming.com/2012/04/05/drag-and-drop-between-multiple-uiviews-in-ios/

Resources