UIView background color affects touches in iOS 5
I had a custom view with subclassed touch responses that was working in iOS 4. On iOS 5, these touches would not respond at all when touched along the bottom edge of the view, if the view’s background color was set to
I have not been able to track this down, but does anyone know if iOS 5 changed the way views respond to touches depending on a transparent background?
I can make no changes to the code other than set the background color to any opaque color like
orangeColor and the view fully responds.
Note the issue does not affect touches elsewhere in the view; only along the bottom edge, anywhere below the last subview added to the view; presumably a clear background is treated as if the view does not exist for the sake of touches when looking at an area of the view that has no content. Change the color, the view has “content” and the touches work!
- iOS: Universal App - Release as iPhone only
- How can I prevent the display on an iOS device from dimming and turning off?
- “No visible @interface for 'BlahDataController' declares the selector 'aMethod:'”
- Check supported architectures of framework in Objective C
- So a CALayer does not contain a content bitmap of a view?
- iPad: file was built for armv7 which is not the architecture being linked (arm64)
2 Solutions Collect From Internet About “UIView background color affects touches in iOS 5”
Instead of using
[UIColor clearColor], try using this:
[view setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:0.1]];
UIView does not respond to touch events when the
alpha is anything below
[UIColor clearColor] sets an
0.0, so you won’t get the touch events. Following the above method, you can receive the touch events on a transparent view.
In case anyone else runs into this problem and wants a better solution than setting a partial opacity for the background, you can set the view’s
opaque property to
NO and then add an empty
drawRect: method. (Tested and working on iOS8, beta 4.)
- How to check if MKCoordinateRegion contains CLLocationCoordinate2D without using MKMapView?
- How to download video from url and save it in to document directory in iOS?
- Conversion to Automatic Reference Counting (ARC): 'Use of undeclared identifier' errors
- Get iPhone phone number label from Address Book
- use UIVisualEffectView to create a blur view, correct on simulator but not on iphone & ipad
- Is OpenGL threadsafe for multiple threads with distinct contexts?
- Chrome IOS – Is it just a UIWebView?
- How do vector images work in Xcode (i.e. pdf files)?
- How to have the Xcode 3.1 compiler warn of assignment operator in an if statement?
- Statically link OpenSSL in XCode
- How to test a iPhone app on my device with developer team member?
- Why UISwitch onImage/offImage properties are not working on iOS 7?
- Persistent UDID equivalent for iOS 7?
- Swift Covariant Generics
- registerUserNotificationSettings not showing prompt iOS 8