No button events in iphone 5 simulator - iphone

When I test my app running in the iPhone 6 simulator everything works as expected. If I however test it in the iPhone 5 or iPhone 5.1 simulators, I can't seem to get button events fired. Im using Xcode 4.5.2, not using storyboards and I have made tests with simple buttons with actions like:
- (IBAction)test:(id)sender {
NSLog(#"YEES");
}
And the actions is connected using drag and drop in the interface builder. I just can't seem to get it fired.. Do you have any idea about what could be the problem?
Update Jan 18:
If I do a "normal" click on a button in the iPhone 5/5.1 simulator nothing happens. If I do a bit "slow" click on a button the button will be "pressed"/selected. If I do a "really slow" click, like holding the button down for 3 seconds I get the button click event! How is this possible??

I found a solution for my case - i added UITapGestureRecognizer to the container UIView, and it intercepts events before UIButtons, and need some time to fail before buttons can handle tap... But it strange that in iOS 6 all works fine
To avoid this we can simply call:
[tapRecognizer setCancelsTouchesInView:NO];

I really suspect this could be the issue of view overlapping.
Please color your views that you are using on the view controllers and check whether any of your view is overlapping your button or not

I had a similar issue with an iPhone 5s simulator. Through trial and error I realized that the button's height in the simulator was 0 or otherwise a small number... The first clue to that was that when I changed its background color - the background did not show in the simulator (on larger simulators, like 6 or 6 plus, it showed as a thin line instead of full height). Then when I added a height constraint, it started accepting click events. That helped me identify the issue, but it was not the solution I was looking for. Initially I laid the button out without size constraints, so it's actual size should have been determined by it's intrinsic size. So instead of the height constraint, I changed the vertical compression resistance of the button to "required". That fixed the issue.

Related

Storyboard view designed properly with Auto Layout and Trait Variations in Interface Builder of Xcode 8 has wrong size in Simulator and Device

I've been working on iOS apps for many years before a longer pause. On my new project I decided to try the new features of the Interface Builder and Storyboards (Swift 3, Xcode 8.2.1). So I've got a working app with precisely defined constraints for all supported devices, following the "regular" and "compact" width/height paradigm. Everything seemed to work and I loved the approach.
I was finalising the first views (and their controllers) for the iPad simulator before I decided to run the app also on an iPhone simulator to check for the layout. It turns out that all works as expected but for ONE view.
This view has the following behaviour:
If in the Storyboard canvas (and even the Assistance Editor, which
looks the same for me, by the way) I selected "view as iPad 9,7" and
run the iPad simulator (of the same screen size), the layout works the way it should.
If in the Storyboard canvas I selected "view as iPhone 5" and
run the iPhone 5 simulator, the layout works the way it should.
If however I select "view as iPhone 5" and run the app on the iPad simulator OR any other false combination, the following happens:
Once the view appears (custom segue, or default push. All the views are inside a navigation controller) it shows the content scaled down/up to the size of the preview size I selected on the Storyboard. Then it animates (scaling from the top left corner) to fill the screen. For instance: If I select "view as iPhone 5" and run on an iPad, the view appears in the left top corner of the iPad simulator having the size of an iPhone 5. Then it scales up to fill the screen having the exact layout I want.
One should add that inside this one view, the layout for all devices looks the same, merely scaled down/up. So it really just comes down to wrong view size.
This all happens ONLY to one of my views, which I all have designed and laid out (constraints) the same way. This happens EVERY TIME, and it happens on the simulator and on real devices.
I was trying various suggestions from the web for the last week and I failed to find any topic (on Stack Overflow) that was able to help me.
I'm lost. I'm glad for any suggestions!
Thank you.
After removing everything from my view step by step and building every single step I found that I had a self.view.layoutIfNeeded() inside my viewDidLoad() which was inside an animation block animating a single subview, but for some reason lead to aforementioned issues. Removing it solved the issue.

Weird iPhone 4 simulator behavior - UITextViews stacked on top of each other

I just finished up my storyboard based iPhone app (I'm developing on an iPhone 5). Just before submitting it to the Appstore, I thought of making sure everything looks fine on an iPhone 4. So I launch my app in the simulator with iPhone 4.
And what I see baffles me. Basically every single view object, particularly textview, are stacked on top of each other. Basically everything scrollable's messed up. In some textviews even, the initial scroll position has been set to say 100px, which means that the textview's showing the middle of the content in a textview and there'sno way to scroll to top.
Every time I make an ajustments to the storyboard view to fit the iPhone 4, the view on iPhone 5 instead looks weird. Most of the time, the stacked objects on iPhone 4 simulator can't even be unstacked.
Am I the only one experiencing this? I cant find any post about it. Could it be that there's something messed up with my simulator? Any setting I've missed? The only solution I can think of now is to have a seperate SB for iP4 and iP5, but I really would rather not go through the pain of doing that. Any comment or idea is greatly appreciated.
How it looks
You need to make sure that your autosizing struts and springs are set appropriately.
The views need to either dock to the top, or bottom and the views that you want to stretch should have the flexible vertical set.

iphone 5 simulator - Cannot click on bottom of screen?

I'm trying to update an app to add support for the iPhone 5. Based on other threads I have seen, I have added the Default-568h#2x.png as specified and I have added some new background images to the app that are sized appropriately. The problem is that the bottom portion of my app does not seem to be responding to touch (I have a page control and an info button).
Additionally, when switching screens (using the following code):
[self presentModalViewController:tableNavController animated:YES];
The bottom of the screen blacks out. This black section is basically exactly where I am unable to touch. Screenshot of this issue is below:
Any ideas on why this would be happening? Why I cannot access this bottom section? Note if I run the regular iPhone 4S or iPad simulator this does not happen. I can access the entire section of the screen.
Edit: Could it be a simulator problem? I do not have a physical iPhone 5 yet, so I am unable to test it on a real device.
Edit2: I have tried both enabling and disabling Auto-Layout on both the views and the applications main window. If I add the following log statement to viewDidLoad:
NSLog(#"Window is: %0.0fx%0.0f", window.frame.size.width, window.frame.size.height);
NSLog(#"View is: %0.0fx%0.0f", viewController.view.frame.size.width, viewController.view.frame.size.height);
I receive Window is: 320x480. View is: 320x548. So it looks like it may be a problem with my window. I will continue to investigate.
Figured it out. The main window was not getting resized although the view was. I deleted the window from my xib, created a new one and re-linked it. That solved the issue.
This can be solved by enabling "Full screen at launch" on the window. Deleting and recreating merely enables this.
A simpler solution is to select the window and switch to the Attributes inspector. Change Size to Retina 4 Full Screen.
A simpler solution is to select the window and switch to the
Attributes inspector. Change Size to Retina 4 Full Screen.
Steven's answer is correct, mostly. However now your window is larger than the screen on the 3.5" devices, and the right size on the 4" devices. Basically you will either have to adjust the window size at run-time if you later have anything that references the window, since that will return the 4" window otherwise.
for instance if you used this in your code
[[[UIApplication sharedApplication] delegate] window]
Just be careful with this, that being said it will work for most applications.

My button doesn't detect touch events on iPhone (Retina 4-inch) simulator, but works in iPhone (Retina 3.5-inch) simulator

I'm getting my app ready for the iPhone 5 using the simulator and I've found a weird issue where a couple of my buttons, in one of my views, don't work in the iPhone (Retina 4-inch) simulator, but work fine in the iPhone (Retina 3.5-inch) simulator. The buttons simply don't do anything when they're tapped. Has anyone else experienced this issue?
I having a difficult time figuring out where to start with this one. Any suggestions on where to start?
Thanks so much in advance for all your wisdom!
You need to edit your MainWindow.xib and enable "Full Screen at Launch". For a more detailed explanation, see Apple's docs:
Important: When creating your window in Interface Builder, it is
recommended that you enable the Full Screen at Launch option in the
attributes inspector. If this option is not enabled and your window is
smaller than the screen of the target device, touch events will not be
received by some of your views. This is because windows (like all
views) do not receive touch events outside of their bounds rectangle.
Because views are not clipped to the window’s bounds by default, the
views still appear visible but events do not reach them. Enabling the
Full Screen at Launch option ensures that the window is sized
appropriately for the current screen.
Complete document from Apple
For me, the solution was to set the size ("Simulated Metrics") to "Retina 4 Full Screen" for the MainWindow.xib. I did not need to alter the size of the other screens (they are still set to None). After changing the MainWindow.xib the bottom area becomes clickable again...
The problem was caused by another control overlapping my buttons due to the way the springs and struts were setup. Adjusting the z-order of the buttons fixed the issue. Thanks, all!
There are two solution to this problem :
If you are using MainWindow follow these steps :
a. Select MainWindow.xib.
b. Select Full Screen at Launch from Windows option available in Attributes Inspector.
If your application doesn't contain MainWindow then just add:
self.view.frame = [UIScreen mainScreen].bounds
in ViewDidLoad.
I solved my prob.
view .origin for 3.5 inch and 4 inch screen are different so, when writing common code for both we need to take care at giving CGRectmake(x,y,w,h);
Set temp. diff background color of diff view so you can check if any view is overlapping or not, to fetch event in 4.0 inch.

i image does not work good in utility app on iPhone app

I working on a utility app. When I run the app in simulator clicking i image at the bottom flips the view in a flash. But when I run the app on iPhone device it behaves abnormally. At times it flips the view in just 1 tap. The other times it does not bother to react even after tapping the image 10 times. I tried with other utility app also - same issue. Thus its not an issue with the code I believe.
Any help to resolve this issue is much appreciated.
Thanks,
AJ
This is a problem because the 'i' button is not very big by default and touches are missed easily.
You need to put another button in front of the 'i' button with the 'Custom' type in Interface Builder, so that it doesn't have any image. Then you can make this invisible button much larger and connect it to the same action as the info button.
You also need to enable "shows touch on highlight" in Interface Builder so that you get the white glow effect when the invisible button is touched.