Ccocs2d UIScrollView Stops Touch Response - ios

I am using a uiscrollview in my cocos2d project, using modification of some cocos2d files and the great CCScrollView class I got from a SO link. It is working fine but when I move to a next scene, the new scene is not responding to touches (whereas it was working fine before).
I am using iOS 5.1 & cocos2d 2.x.
Any suggestions?

Ok, you need to do this:
[aScrollView removeFromSuperview];
I'm not quite sure why since in the dealloc of CCScrollView you have:
[self removeFromSuperview];
I guess its being retained somehow? Anyway, it works.

Related

willRotateToInterfaceOrientation not called on iOS8

I'm using the VFR PDF viewer library in my app, where I present it thus:
ReaderDocument *document = [ReaderDocument withDocumentFilePath:pdfFile password:nil];
ReaderViewController *vc = [[ReaderViewController alloc] initWithReaderDocument:document];
[self.navigationController pushViewController:vc animated:YES];
If I run on iOS7, everything works fine.
If I run my app on iOS8, the willRotateToInterfaceOrientation method in ReaderViewController never gets called, so when the device is rotated the document doesn't get reformatted correctly.
However, if I run the demo app that comes with the library on iOS8, the willRotateToInterfaceOrientation in ReaderViewController does get called, which leads me to believe the library is ok, and I'm doing something wrong (or neglecting to do something) in my app.
I'm rather puzzled at this behaviour. Why doesn't willRotateToInterfaceOrientation get called in my app on iOS8, but it does under the other variations? How can I try to track this down?
I finally managed to resolve my problem; here is what the issue was in case anyone else has the same problem.
My ReaderViewController was being presented from a class that had implemented viewWillTransitionToSize:withTransitionCoordinator:, so the deprecated methods on child view controllers weren't being called.
Also in that implementation it wasn't calling
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]
and so the viewWillTransitionToSize:withTransitionCoordinator: method of all child view controllers wasn't being called either.
The fix was to add a call to
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]
into the parent VC's viewWillTransitionToSize:withTransitionCoordinator: method, subclass ReaderViewController, then add a viewWillTransitionToSize:withTransitionCoordinator: to my subclass to call the appropriate methods in ReaderViewController.
Simply because willRotateToInterfaceOrientation is no more called in iOS8, it is deprecated.
If the new rotation methods are not implemented, and a project is
compiled with the iOS 8 SDK, the view controllers -will not receive
calls- to the deprecated rotation methods.
A similar question to yours can be found here
Citation of #mluisbrown :
The rotation methods are deprecated in the iOS 8 SDK. This will have
no effect at all on apps built with the iOS 7 SDK, even running in iOS
8 and probably several future versions of iOS.
I struggled a bit with some kind of a similar problem to yours. I tried following Apple recommendation to use viewWillTransitionToSize, which in my case did not solve my problem because this only gets triggered on changes from regular to compact for example an not on rotation.
viewWillTransitionToSize:withTransitionCoordinator: to make
interface-based adjustments.
Which is detailed in apple documentation
Also a video of WWDC 2014 explains this but I can't remember which video it was. Perhaps the one on What's new in Cocoa touch or the one on View Controller Advancements in iOS 8.
EDIT
Note that in my case viewWillTransitionToSize, as explained, was not called because I wasn't changing from regular to compact so there was no size transition, strictly speaking for Apple.
The only solution I fount was to handle this manually in the viewDidLayoutSubviews of the corresponding view controller.
In my case I wanted to keep track of the top cell displayed in a tableview with autolayout. As it wasn't tracked automatically by the system, I had to check that manually and scroll manually to the adequate cell on rotation. That's why I did it that way. It's quite "heavy" but works in my case.
I would also be interested if anyone has an easier solution.

How to change the Content Node for a CCSrollView in SpriteBuilder

I'm building a game that requires levels. These levels, so that they all fit onto one page I have had to add them to a CCScrollView. This view loads automatically, as I have set in the SpriteBuilder App. The CCSrollView has been added in the MainScene.ccb file, and the content node for the scroll view is Level.ccb. What I'm trying do is have a button that is in the Level.ccb that changes the scene/content node to a level which is called Gameplay.ccb. I've tried writing the code to change the scene in the MainScene.m and Level.m files in Xcode. However these bring up an error. I'm still learning to code, so sorry if the question has been asked or has a really easy solution
- (void)levelOne {
CCScene *gameplayScene = [CCBReader loadAsScene:#"Gameplay"];
[[CCDirector sharedDirector] replaceScene:gameplayScene];
}
This piece of code is how i would switch the scene without the scrollview
If you do not understand what my problem is and would like the code send me a message and i will email you the source code
Thanks!

UIView Rotation Magically Happening

I was given a project that was started by someone else who no longer works here.
I have a UITabBarController which holds some UIViewControllers.
If the application is running on iOS 6, everything runs fine, However as soon as I run it on iOS 5, all UIViews are rotated 90 degrees and given an origin value of something around -100 to -300
I have been able to loop through all view controllers of the tabBar and set
myView.transform = CGAffineTransformMakeRotation(0.0);
myView setFrame:CGRectMake(0,0,1024,748);
The initial view controllers on UITabBarController appear correctly, However, if I ever try to launch a modal view controller, everything is stuffed again. including the modal.
I am running out of ideas on how I could fix this once and for all. I couldn't find anything in the code that rotates the views.
What I could deduce is
on iOS 6, the first subview of the main view holding the UITabBarController is UILayoutContainerView
but on iOS 5 the first subview is of class UIView
If this is an issue with UILayoutContainerView not being supported in iOS5, how can I make the application backwards compatible now?
Note: we only support Landscape (Right/Left) and only on iPad.
Also, I have noticed that if the user rotates the application before initialiazing the UITabBarController and its sub controllers. everything works fine. Even if you re-run the application and not rotate again, still works.
Thanks in advance
If you want your application to stick in landscape mode you the blow code, the issue resides in iOS 5, many people face this issue
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL returningValue=NO;
if (interfaceOrientation==UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
returningValue=NO;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
returningValue=YES;
}
return returningValue;
}
Apparently, this is where I went wrong
For iOS 5
when setting the view of the main window of the application, one must use
[self.window addSubview: tabBarController.view];
Instead of (iOS6 only)
[self.window setRootViewController: tabBarController];
I am unsure how that changes everything, and the reason it won't work for iOS 5. Nevertheless, it worked.
Thanks everyone :)

IBAction in Xcode 4.5

Anybody experiencing no response for IBAction touchUpInside in Xcode 4.5, deployment target iOS 5 as well? It works in simulator for me having iOS6, but not iOS5.
I had this same issue because I was using a tap gesture. You should be able to keep your existing code by adding the line below. This will keep your tap gesture from killing any taps on interior buttons and such...
yourTapGesture.cancelsTouchesInView = NO;
Edit:
I have found the solution. I was adding a tap gesture to the view, which was overriding the view's ability to detect a touchUpInside action on any buttons since they are part of the view as well. So what you should do is either remove the gesture recognizer or make it specific to a certain object. For example, I added the touch gesture to the specified part of the view that was not on the subview (I created a new object / outlet and labeled it as such). Still not sure why it's different in 5.1 vs. 6.0, but this should help you.
Original Post:
I am having the same issue. I have a project where buttons on a subview are clickable on version 6.0 of the simulator but not version 5.1. I have some gesture recognizers in there as well but commented them out to see if they were the issue and they are not. The only thing I have found is that the buttons are sometimes clickable on a touch up outside action (even though they are programmed for touch up inside), so I am not sure if maybe Apple changed the eNums for button actions? If I come up with a solution I will be sure to provide it here.
I just created a new demo project. I added a button to a view, handle touchUpInside, built and tested using Xcode4.5 on both deployment target ios6 and ios5 - both worked just fine. Try with a demo project yourself - won't take more than a few min.

icarousel with cocos2d issue

Every body i am integrating icarousel with cocos2d using uiviewwrapper and after that i have done with icarousel is working fine in simulator but on ipad it make some problem that is its first and last options are responding normally as it does but in between options uibuttons are not responding when selected and thay are working when that are at some specific angle not in front view .I have searched alot but i could not find any solution for that as there is not a single warning or error when app builds.
All suggestions will be welcomed. Thanks
https://github.com/nicklockwood/iCarousel/issues/85
In the appDelegate function delete the line
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];
and replace the same with
[CCDirector setDirectorType:kCCDirectorTypeDefault];
setting the [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] will cause unexpected behaviour in iCarousel.
It's possible that Cocos may be interfering with the UITapGestureRecognizer that iCarousel uses to intercept taps and forward them to the item views.
That would explain why you can tap the side views but not the frontmost view, since it's gestures are treated differently.
Try poking around in the code and adding some breakpoints to the gesture handling logic to see if you can see where it's failing.
Alternatively, send me a working code example and I'll take a look.

Resources