I can not load SKView scene in iOS 7 - ios

I have a game in AppStore made with SpriteKit. Its deployment target is 7.0. Compile and runs fine until I upgraded to XCode 7.3.
I don't have any problems with IOS 8 or 9 but with 7 it simply does not load my scene.
My code to load my scene is:
#implementation levelsViewController {
SKView *_skView;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
// Configure the view.
if (!_skView) {
_skView = [[SKView alloc] initWithFrame:self.view.bounds];
LevelsScene *scene = [[LevelsScene alloc] initWithSize:_skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
_skView.showsFPS = NO;
_skView.showsNodeCount = NO;
_skView.showsPhysics = NO;
// AFTER A WHILE< NEVER SHOW THE SCENE. I DONT HAVE ANY PROBLEM WITH IOS 8 or later but with 7 :(
[_skView presentScene:scene];
[self.view addSubview:_skView];
[self.view sendSubviewToBack:_skView];
...
}
Any help would be appreciated!

Finally found the workaround.
My Scene use this class from github https://github.com/zackhsuan/ZKPulseView.
I don't understand why, but this routine works perfect until XCode 7.3. The behavior is weird, because it's works perfect for iOS 8 and 9 but in 7, show the effect perfect, but when I press the button with effect and the scene call something with spritekit got this strange behavior.
So, just does not used this routine exclusively for ios 7 and works.

Related

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 :\

Map rotation horribly slow on ios8

I got the following code in a VC in an old project (no storyboard, pure code) :
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView = [[MKMapView alloc] initWithFrame:CGRectInset(self.view.frame, 10, 10) ];
[self.view addSubview:self.mapView];
self.view.backgroundColor = [UIColor redColor];
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.view.translatesAutoresizingMaskIntoConstraints = NO; // <--- this line
}
If I comment the last line, a rotation from portrait to landscape or the other way is about 3 seconds under ios8 !! Also, occasionally at random times Unable to allocate render buffer storage! errors appear.
If I don't comment it, it's almost instantaneous (0.7seconds).
It seems it is only related to mapviews, the other views/VCs rotate just fine.
Under ios7 the rotation is fast in any case with that line commented or not.
Why ? And why is only the mapview affected ?
Edit: It seems clearly the autoresizingmask is wrong. If in viewDidLoad I set its value to none and manually change the frame in willRotate, it works fast.
I had the same problem when the application came back from the background. It froze a few seconds and then it worked again. I used a .xib file without Autolayout.
When I updated the .xib file and added the Autolayout option the problem was gone. I came up with this idea because you wrote that autoresizing was the problem in your solution.

EXC_BAD_ACCESS when retrieving views from transition context on iPhone 4

I have the following code, which works perfectly on my iPhone 5 and all the iPhone simulators, but it crashes on my iPhone 4. I get EXC_BAD_ACCESS on the last line where I pass UITransitionContextToViewKey to my transition context.
I have a clean analyze and build, and the same happens for both UITransitionContextFromViewKey and UITransitionContextToViewKey.
My iPhone 4 is on iOS 7.1.2, my deployment target is 7.0, targeted build base SDK 8.0.
Anyone knows what to do here? thx.
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
// get transition parameters from context
UIView *containerView = transitionContext.containerView;
UIViewController *destinationViewController =
[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
if ([destinationViewController.title isEqualToString:#"ListController"]) {
// get source and destination views
UIView *sourceViewSnapshot = [self.view snapshotViewAfterScreenUpdates:YES];
UIView *destinationView = [transitionContext viewForKey:UITransitionContextToViewKey]; // EXC_BAD_ACCESS
// ...
}
The viewForKey method is iOS 8 and up, but the viewControllerForKey method is supported in iOS 7. A small change to your code gets the view in iOS 7:
UIView *destinationView = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view;
From the documentation:
UITransitionContextToViewKey
Available in iOS 8.0 and later.
You can't run that code on iOS 7
You might want to add runtime system version checks and branch out to a iOS 7 compatible code at this point if you want to maintain compatibility with this version of the system

Strange appearance of the status bar after upgrading to ECSlidingViewController 2

It seems that one particular aspect of iOS programming is to diagnose these weird, seemingly trivial yet frustratingly obscure small problems.
So today, I was happily woking on my recent iOS project, and I decided to upgrade my project to the latest version ECSlidingViewController, what harm could it do right? Just update a few deprecated methods that's all.
So I did all of that. Everything works fine, beautiful. However, I noticed that the status bar is behaving strangely! It is not appearing when I display one of my underLeftViewController, and it is in a weird shade when I push segue that particular underLeftViewController into one of its subsequent VC. What?? How could this be happening? Anyway, a picture is worth a thousand words:
So here is it acting nice and normal:
Now it disappears!!!:
Now it has a weird shade!!!:
And here is a picture of the app with the sliding view controller slided out:
I must have done something crazy to my status bar somewhere, then I thought.
So I looked into my implementation file for the VC where statusbar is acting crazy. It is in fact a subclass of UINavigationController, and its viewDidLoad is empty except with the [super viewDidLoad] line. So nothing suspicious here.
The run test page is in fact the rootViewController for the navVC, so I looked into it. I put all of my view setup code in its viewDidLoad, and this is what it looks like:
- (void)viewDidLoad
{
[super viewDidLoad];
// remove advanced button
self.navigationItem.rightBarButtonItem = nil;
self.navigationController.view.layer.shadowOffset = CGSizeMake(1, 0);
// setupGaugeView
[self setupGauge];
// add run test button
[self setupRunTestButton];
// setup notification container
CGRect notificationContainerFrame;
if ([WRGlobalHelper currentDeviceVersion] >= 7) {
CGFloat statusBarHeight = [WRGlobalHelper statusBarHeight];
notificationContainerFrame = CGRectMake(0, [[self.navigationController navigationBar] bounds].size.height+statusBarHeight, self.view.bounds.size.width, 1);
for (UIView *subview in self.view.subviews) {
CGRect newFrame = subview.frame;
newFrame.origin.y += [WRGlobalHelper statusBarHeight];
subview.frame = newFrame;
}
} else {
notificationContainerFrame = CGRectMake(0, [[self.navigationController navigationBar] bounds].size.height, self.view.bounds.size.width, 1);
}
self.notificationContainerView = [[UIView alloc] initWithFrame:notificationContainerFrame];
self.notificationContainerView.clipsToBounds = NO;
self.notificationContainerView.layer.backgroundColor = [UIColor clearColor].CGColor;
[self.view addSubview:self.notificationContainerView];
// some other unrelated stuff omitted....
}
And the `viewDidLoad's for the VCs where the status bar is acting normal or bizarre but with shade is all quite plain as well, they look like
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.view addGestureRecognizer:self.slidingViewController.panGesture];
}
Mind blown and I give up at this point. I've spent nearly 2 hours on this single issue already, and my brain hurts at the thought of the disappearing status bar. The almighty and omniscient SO, please help me! Thank you very much!
The status bar is not disappering, the text is just changing its color based on its assigned Style.
This answer will help

Using UIImagePickerController in iPad Mini iOS 7

I have an app targeting iPhone. The UIImagePickerController works fine on iPhone, but when I open it with iPad Mini on iOS 7, the top part of UIImagePickerController was hidden, which hide the front/back camera toggle button. How can I solve this?
Update:
I observed through subview hierarchies that the "CAMFlipButton" has wrong frame:
<CAMFlipButton: 0x176e6250; baseClass = UIButton; frame = (310.5 9.5; 48 70); opaque = NO; layer = <CALayer: 0x176e63c0>>
I had the same issue; it seems to affect only the iPad Mini (but only the non-retina version), on both iOS 7 and 8. Not sure why not many people faced this issue, but I couldn't find a working solution or workaround.
So what I did (what I hacked!) is I detect when this happens (when the button ends up outside the window bounds), and correct it, by moving the button back into the window, and adding my own image to the button.
#interface MyImagePickerController : UIImagePickerController
#end
#implementation MyImagePickerController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
showFlipButtonInSubviews(self.view);
}
void showFlipButtonInSubviews(UIView *view) {
if ([[[view class] description] isEqualToString:#"CAMFlipButton"]) {
if (view.x + view.width > UIScreen.mainScreen.bounds.size.width + 5) {
// Fixes this: http://stackoverflow.com/questions/20895993/using-uiimagepickercontroller-in-ipad-mini-ios-7
// Happens on iPad Mini non-retina only
view.x = UIScreen.mainScreen.bounds.size.width - view.width - 10;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 23, 16)];
imageView.image = [UIImage imageNamed:#"switch-camera"];
[view addSubview:imageView];
}
} else {
for (UIView *subview in [view subviews]) {
showFlipButtonInSubviews(subview);
}
}
}
#end
Why UIScreen.mainScreen.bounds.size.width + 5 you ask? Simply because on the iPad Mini retina, that button has 4 pixels outside the window, but it still shows correctly, so I don't want to apply this hack then.
My switch-camera image looks like this:
(hard to see, it's white! right-click or drag it around to see it...)

Resources