Image missing from distribution - ios

I am having an issue where an image is missing, but only when built for distribution. Also, it only occurs on the iPhone 5, but not for the iPhone 4 or 4S.
This is a screenshot when built for development, on the simulator.
And this is a screenshot when built for distribution, on an actual iPhone 5.
I have a single target for both development and distribution. Relevant code:
int deviceNumber = 4;
if([UIScreen mainScreen].bounds.size.height > 500)
deviceNumber = 5;
MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height) panels:#[panel1,panel2,panel3]];
if(deviceNumber == 4){
[introductionView setBackgroundImage:[UIImage imageNamed:#"One Degree_Iphone4_Background.png"]];
}
else{
[introductionView setBackgroundImage:[UIImage imageNamed:#"One Degree_Iphone5_Background.png"]];
}
And within MyIntroductionView.m, the relevant code is:
-(void)setBackgroundImage:(UIImage *)backgroundImage{
self.BackgroundImageView.image = backgroundImage;
}
-(void)buildBackgroundImage{
self.BackgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
self.BackgroundImageView.backgroundColor = [UIColor clearColor];
self.BackgroundImageView.contentMode = UIViewContentModeScaleToFill;
self.BackgroundImageView.autoresizesSubviews = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:self.BackgroundImageView];
}
buildBackgroundImage is called within the init function.

I'm not 100% sure this is still the case but I know it used to be:
The iOS Simulator is not case-sensitive with regard to external filenames (such as your images). So if the image is named "myImage.png" and your program asks for "MyImage.png", the simulator will correctly find and load the image.
However when you try and run it on the device, it is case sensitive, and will not accept the incorrectly-cased file.
So double check that your capitalization of the file itself is identical to what you're asking for in your program. Hopefully that will fix your issue right up.

Related

I am getting a large black bar at the top and bottom of the screen in all simulator

this is code written in CDVViewController.m based on this only its showing content. Iam new to Cordova can anyone help me?
-(void)createView
{CGRect webViewBounds = self.view.bounds;
webViewBounds.origin = self.view.bounds.origin;
self.webView = [self newCordovaViewWithFrame:webViewBounds];
self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[self.view addSubview:self.webView];
[self.view sendSubviewToBack:self.webView];
}
-(UIWebView*)newCordovaViewWithFrame:(CGRect)bounds
{
return [[UIWebView alloc] initWithFrame:bounds];
}
Sounds like you did not include a launch storyboard (or launch images for all expected sizes). Add one of those to your project and you should be fine.

Since the last Xcode update I can't work with images

This is the basic code I use to add an image named "Background.png" to an UIImageView:
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:#"Background.png"];
imageView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:imageView];
Since the last Xcode update the resource can't be loaded.
I tried running on an iPhone 6 - iOS 10.3 and the Simulator - iOS 11.0
For some reason even though the iOS deployment target is version 10.3 the simulator runs on iOS 11.0
The image is there, in the same folder as the project named: "Background.png"
I've been doing the same thing for years and now it has stoped working.
Anyone had a similar issue?
You may want to utilize the purpose of Assets.xcassets. Put your assets there and you can easily use your images. Note that you do not have to put the image's file extension. It's easy, like so:
UIImage *markerImage = [UIImage imageNamed:#"marker"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:markerImage];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];
I have an image in my Assets.xcassets named marker.
Edit: this is tested, I made an Objective-c project just for this question :)
I had the same problem and i solved it as follow:
Simply Select your image, then check the box linked to your projet name in "Target Membership" (on the Right Window)
is it working ?
There is a Screenshot if needed:
https://i.stack.imgur.com/gTOGJ.png

UIView issue with iPad Air 2. Touches go through, any ideas why this might be?

So I have a custom UIView class (which I call UIStageView) that emulates the look of a prompt in which the background is darkened and its view brought to center (code below). Now, it works perfectly when run on any iPad EXCEPT iPad airs.
For some reason, touch immediately goes through the UIStageView and into its parent view. Any reason why this might be? I'm running the project on iOS 8.1 and even when I revert back to 7.1 the bug happens. Note that this problem only happens on iPad Airs (physical and emulator). When run on iPads 1-4, it works.
// UIStageView
- (id)initWithFrame:(CGRect)frame withTarget:(UIView *)target {
// Init Background
CGFloat screenWidth = target.frame.size.width;
CGFloat screenHeight = target.frame.size.height;
CGRect rFrame = CGRectMake(0, 10, screenWidth, screenHeight);
if (self = [super initWithFrame:rFrame]) {
[self initSubWithFrame:frame withTarget:(UIView *)target];
[self initExtension];
self.userInteractionEnabled = true;
NSLog(#"StageView inited! :)");
}
return self;
}
- (void)initSubWithFrame:(CGRect)frame withTarget:(UIView *)target {
[self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:.8]];
_properFrame = frame;
_entranceFrame = CGRectMake(frame.origin.x, frame.origin.y-frame.size.height/2, frame.size.width, frame.size.height);
_babyView = [[UIView alloc] initWithFrame:_entranceFrame];
[_babyView setBackgroundColor:[UIColor whiteColor]];
_babyView.layer.cornerRadius = 15;
_babyView.layer.masksToBounds = YES;
[self addSubview:_babyView];
_target = target;
_indent = 5;
}
Basically, the way my code works is that the UIStageView itself becomes relegated to serving as a background while the _babyView becomes the main view and is what gets interacted with by the user.
I also have a method set up that removes the UIStageView from its parent view when tapped.
This works perfectly on any iPad I've tried (physical and emulator) EXCEPT iPad Airs. Any ideas? :\
Fixed it! As it turns out, declaring #property (nonatomic)float alpha was causing UIView to malfunction. I noticed my UIView wouldn't accept touches at all on either iPad Air or iPad Retina when I didn't explicitly set it (i.e. _alpha = .5) and it would fail only on iPad Air when I did set it (i.e. _alpha = .5).
EDIT:
Just found out that alpha really is a reserved word and I just never noticed. My bad :\

Image is showing on simulator but not on a real iPhone

So I got this piece of code, I want to show a picture on my view:
imgLogo = [[UIImageView alloc] init];
[imgLogo setFrame:CGRectMake(60, 200, 200, 200)];
[imgLogo setImage:[UIImage imageNamed:#"MyFrigginAwesomeLogo"]];
[self.view addSubview:imgLogo];
But the problem is that it works correctly when testing it on the simulator(iOS 7) but it doesn't show anything on my iPhone(4S with iOS7) itself.
Answer added from Comment:
The iOS devices are case sensitive, but the simulator is not. Make sure you are trying to load the exact filename in order for them to be found.
Try using the designated initializer for UIImageView instead of just init:
NSString *logoName = #"MyFriggingAwesomeLogo";
imgLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:logoName]];
imgLogo.frame = CGRectOffset(imgLogo.frame, 60, 200);
[self.view addSubview:imgLogo];
It's also possible that you've added the image resource to only the simulator target. In your bundle settings Build Phases, make sure you have the image listed in Copy Bundle Resources.

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