Is it possible to display a tap-to-focus blue box when a custom overlay is used in a UIImagePickerView and when showsCameraControl attribute is set to FALSE?
The modal camera view already supports touch-to-focus. You need to make your overlay view "transparent" to touches.
Subclass a UIView as OverlayView and add something like this. In my overlay view I have two buttons, which should of course not be transparent for touching.
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
if (CGRectContainsPoint(infoButton.frame, point) || CGRectContainsPoint(snapButton.frame, point)) {
// touched button
return YES;
}
return NO;
}
There are probably other and more elegant ways to do this.
I think you would also have to add the little "focus rectangle" on your view programmatically.
you can use a custom button for that with alpha value zero. And with text that you want to display
Related
I have a MapView, Over which i have added a UIView (0, 216, 320, 200) contain 10 UIButtons. This UIView is to work like a menu, and Shows and Hides on a certain button action.
The problem here is, While the Menu is showing, when i tap a button single ime, it works perfectly, but tapping it very quickly multiple times makes the MapView Zoom(Which is under the UIView which contain the button). It means the touch event is passing to MapView.
Detail: Tapping on the button very quickly cause in MapView Zoom, and the Button Action performs when you stop tapping.
How can i prevent that?
What you could do is disable user interaction for the duration of your button's handler. So in the selector do:
-(void)buttonSelector:(id)sender {
_mapView.userInteractionEnabled = NO;
// ... do what your button needs to do
_mapView.view.userInteractionEnabled = YES;
}
Of course, this assumes your button gets the event before the map view... which I think it should because it's on top of the map view.
To handle the rapid tapping, you could create a subclass of UIButton and use the following code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_mapView.userInteractionEnabled = NO;
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
_mapView.userInteractionEnabled = YES;
}
In the builder change the class of the UIButton to your subclass. If you debug the touch in the set passed to the touchesEnd method and look at the tapCount, you'll see all your taps have been caught here.
Yes, so the problem was, I was adding UIView as subview over MapView.. I fixed it by adding the UIView as subview on self.view
I'm working on a photo Collage application. I want to perform an action on image view so any one can help me to solve my problem. when i pick image from photo library and shown on image view after when double click on image view i want to push or present a new view to crop this image .....so anyone tell me what i do to solve my problem...
Use a UIButton of type custom and put an image inside it. And you are done.
Add the Gesture for ImageView
UITapGestureRecognizer *sg=[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(HandleEvent)];
sg.numberOfTapsRequired=2;
[BottomBar addGestureRecognizer:sg];
[sg release];
and do your task here:
-(void)HandleEvent
{
// your task
}
Thanks
You should use a UIButton instead of an UIImageView. You can set its style to custom and then asign it an image. UIButton provides all the methods for double tap already built in.
If you are using UIImageView, make sure you use setUserInteractionEnabled:YES. Then you need to check your touches in touchesBegan, ended, (canceled).
You are set on using UIImageView, you will have to subclass UIImageView and override the touch methods you want to intercept. For example:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Call super to make sure you don't lose any functionality
[super touchesBegan:touches withEvent:event];
// Perform the actions you want to perform with the tap.
}
Using UIButtons as replacements for your UIImageViews is a great idea you can just drag a connection from each button to an outlet in your view controller and handle the action. You can set the background image on the buttons as you are doing currently with the UIImageViews. Set your button type to custom and you'll be good to g
If you are using UIImageView class ,first set setUserInteractionEnabled:YES . Then set UITapGestureRecognizer event to image view.
try this
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint locationPoint = [[touches anyObject] locationInView:self.view];
CGPoint viewPoint = [imageView convertPoint:locationPoint fromView:self.view];
if ([imageView pointInside:viewPoint withEvent:event]) {
//do something
}
}
Make a button, and clear its color. On the back of button, put your image view, so that your imageview seems to be visible and the button doesn't. Now attach event to the button.
Is it possible to create two button shown as below image? It may seem like you should use UIButton or UIImageView but if i click to area 1, it stills acts as clicked to button 1. Button 2 should be fired when I click to the area 1 as well!
Failing the above responses being acceptable, you could implement a custom subclass of UIButton that overrides pointInside:withEvent:.
Assuming your view is exactly square and the graphic exactly circular and filling the entire square, an example might be:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// check that the point is at least inside the normal rect
if(![super pointInside:point withEvent:event]) return NO;
// we'll assume a square view with an exact circle inside, so
// the radius of the circle is just half the width
CGFloat radius = self.bounds.size.width*0.5f;
// the point (radius, radius) is also the centre of the view, so...
CGFloat squareOfDistanceFromCentre =
(radius - point.x)*(radius - point.x) +
(radius - point.y)*(radius - point.y);
// if the point is too far away, return NO
if(squareOfDistanceFromCentre > radius*radius) return NO;
// otherwise we've exhausted possible reasons for answering NO
return YES;
}
You can make circular button by cutting the layer and set radius of you button.
[[button layer] setCornerRadius:8.0f];
you can also try with change radius.
Yes, of course is possible.
You can connect a single action with more than one selector through IB.
You can also call directly the method fired by button2 from inside the method fired by button1.
It quite tricky, but possible:
You can use only one button, but put some verification after event touchUpInside. You should calculate if this touch point are inside the circle of "button1". For this task you need to have some mathematic knowledge - How do I calculate a point on a circle’s circumference?
Set userInteractionEnabled to NO for the smaller Button 1. All events will go to the larger Button 2.
I have created two round rect buttons for this purpose, one of them is long and thin, and the other one is more wide. Together they build a shape like a chubby plus sign, which is pretty close to a circle, considering apple accepts 44 px as the minimum confortably pressable size. If you want the image to change, set another image to its imageView for highlighted state and connect several actions (touchup wont be sufficient if you want to immitate buttons highlighted state on the image view)of the two buttons. Alternatively you can add observers and alter highlighted state of the imageview according to the buttons
A clean way to deal with pointInside on a circular button is this:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
if (![super pointInside:point withEvent:event])
{
return NO;
}
BOOL isInside = (pow((point.x-self.frame.size.width/2), 2) + pow((point.y - self.frame.size.height/2), 2) < pow((self.frame.size.width/2), 2)) ? YES:NO;
return isInside;
}
You can ditch the 'isInside' variabe, but this way is easier to test.
In My view there is reset button .i need userinteraction disabled except for that button .how can i do that can any one share the code.thanks in advance?
btn1 is your button, self.view - your view
for (UIView *view in self.view.subviews)
view.userInteractionEnabled=NO;
btn1.userInteractionEnabled=YES;
For all the elements there is a property userinteractionenabled. Set it to false
yourelement.userInteractionEnabled = NO;
Also place your UIButton on top of your view hierachy.
Other option is to place a tranparent UIButton on your entire view and your UIButton on top of this view. This way only your UIButton is touch enalbed. Other touches would be taken in by the transparent button which does nothing.
Sligthly better approach, define a "magic value" that will help you :
#define kDontDisableUserInteraction 3928473
then set this value as the tag of your button you don't want disabled:
[resetButton setTag:kDontDisableUserInteraction];
you can now create a function in your superview's class :
- (void)setInterfaceEnabled:(BOOL)newEnabled {
for (UIView *subview in self.subviews) {
if (subView.tag != kDontDisableUserInteraction)
continue;
subView.userInteractionEnabled = newEnabled;
}
}
That allows you to create other non-disableable buttons simply by giving them the right tag (which can be whatever int value you want, not only 3928473, depends on your #define).
I have a draggable view that a user will touch, but some rectangles of it will have no image (alpha 0).
When a user clicks the transparent region (I am able to construct the transparent region without the alpha info), I want the view (same class) below the transparent region to detect the touch.
My strategy is to let the view ignore the touch when user touches the transparent area and hope the view below it will automatically catch the touch event. But I'm not sure if this will work. (setting things up to test this will take some time)
Should I take a different approach or the above strategy would work?
Thank you.
Try overwriting the method hitTest:withEvent: in the superview. You can make hitTest:withEvent: return the view you want to handle a given event.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *v in self.subviews){
CGPoint pointInB = [v convertPoint:point fromView:self];
if ([v someConditionYouMayWantToTestFor]){
return v;
}
}
return nil;
}
The method someConditionYouMayWantToTestFor is where you test if you want the subview to capture the event or not.