Freeform Container UIView - objective-c

I am trying to understand if something like this is possible and if yes how can i go about achieving this.
i want to create a UIView that it is a container for other views that respond based on the below picture. i know that a UIView is a container of other UIViews. what i want to be able to do is to be able to touch on a UIImageView and when i am dragging it in the main View, if it gets out of bounds on one side, to be shown on exactly the opposite direction like shown on the image. i hope i managed to explain the question correctly.
Click Here for the Description

You can achieve that very easily by implementing the container UIView's touch methods:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
In touchesMoved you can check for your UIImageView's origin. If it crosses the boundaries (x, y less than 0 or bigger than the container's dimensions) then simply reposition its frame by your desired offset.

Related

Interactive touch display

I'm looking to intercept all touch events on a parent UIView and display where the user touches but still bubble those touch events to children views i.e.. UIButtons, UITableViewCell, etc. so those children interact via their default manner.
I have no issues displaying touch events interactively on UIView using basic delegate methods:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesBegan:touches withEvent:event];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesEnded:touches withEvent:event];
}
My issue at this point is bubbling these events to next responder when UIView contains other interactive children views such as UIButtons. touchesBegan: is never fired on parent view when tapping a button so I'm not able to display something "pretty" to user when taps buttons.
Is there a better way other than creating category for UIButton, UITableViewCell? Thanks
Here is an example of what I'm looking to do anytime user touches the screen... (notice the white circle when user touches buttons):
https://m1.behance.net/rendition/modules/154366385/disp/9532a948c71e28ffda2219600c05ffd9.gif
You can do it by creating a subclass of UIView.
The view should be on the top of the view hierarchy and its size should be full of the screen.
All touch events will be sent to this view. If you return NO in the pointInside:widthEvent: method, the touch event will be sent to the lower objects.
#implementation MyView
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
{
// show bubble here
return NO; // send touch events to lower layer objects.
}

How do I forward touch events to a view behind a uicollectionview?

I have a uicollectionviewcontroller which I use to create a small toolbar at the bottom of the screen. I add the view of the uicollectionviewcontroller to another viewcontroller's view. My problem is that it won't forward touch events to a view underneath it. I did move it to the bottom and that worked for a while but now I need to use 2 uicollection views.
How am I supposed to forward touch events to views beneath a uicollectionviewcontroller's view?
In case the question is still relevant, the following can be used to achieve touch forwarding.
Subclass UICollectionView
Overwrite - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesEnded:touches withEvent:event];
[self.yourCustomDelegate forwardTouches:touches withEvent:(UIEvent *)event];
}
That is how UICollectionView can keep its ability to respond to user interaction, and the same time forward received touches.
As i think you can add your toolbar as footer of UICollectionView and it will work
have a look into this link How to Add Header and Footer View in UICollectionView

Simple Tappable Non-Rectangular Shape

I have to create a very simple GUI for an iPad application.
I have a 1024x768 png and I want to use this file for the GUI. I have to make an area of this png tappable and able to run some action. This area is not a rectangle (it's a trapezoid) so I can't create a button. Is it possible somehow?
you can do it in code by overriding - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event and - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event in the view that's displaying the image. that'll mean you have to decide whether a point is within the touch area of the image.
Make a UIImageView that displays an image which shows the trapezoid and is otherwise transparent.
Turn on the UIImageView's userInteractionEnabled to make it tappable.
Put a UITapGestureRecognizer on the UIImageView to respond to the tap.
In the tap gesture recognizer's action handler, respond only if the point where the user tapped is non-transparent. To learn whether the point the user touched is transparent, see Retrieving a pixel alpha value for a UIImage.

Detecting touches on a NSOpenGLView

I have added an NSOpenGLView to my MainMenu.xib file, and have implemented drawRect to draw to it, this works great, so far so good.
How do I detect touches on the screen? I imagine I could perhaps dump some transparent buttons or something over the NSOpenGLView area in Interface Builder?
The application is simple, i just need to know which area of a grid has been touched.
No need to add transparent buttons or overlays.
I'm assuming this is for the phone because you mentioned Cocoa Touch, but I'm not aware of NSOpenGLView for the phone. You need to look at the Apple example and create an EAGLView by overriding +layerClass in your subclass thus:
+ (Class)layerClass {
return [CAEAGLLayer class];
}
Next, Make sure "User Interaction Enabled" is checked in IB.
Finally, implement the touch method calls:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
These will tell you where users touched the surface, and with how many fingers. You can do the rest from there. Try creating the template OpenGL project and looking at that. In addition, Jeff LaMarche has some good iPhone OpenGL tutorials on his blog: http://iphonedevelopment.blogspot.com/

iphone: How do I get the location of a touch down event?

I have an empty View-Based app. I'd like to do something with the x,y coordinates of every touch down on the screen. How do I do this?
Override the
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
function (from the NSRespondrer class). You can override it from your view class. The 'touches' variable hold a set of 'UITouch' instances that you can query for the location in the view.