Irregular shaped buttons using OBShapedButton with hidden image - objective-c

I am trying to make an irregular shaped button with the OBShapedButton class. That's ok, created it without any problem, however I need the image to be transparent. So, I just want an area from the image which will be clickable, but the image won't be seen.
I tried setting alphas on image, imageView and on the button itself, however it doesn't work neither way.
How should I do it?
Maybe it could be done by something else, not an UIButton, but unfortunately I didn't find anything on the net that I could understand and use.

Ok, so the easiest way on how to do this is:
Subclass UIButton and add touchesBegan, touchesEnded, touchesMoved,
touchesCancelled.
Then on touchesBegan, hide the image of the button and show the correct image in background.
And finally on touchesEnded or touchesMoved, show again the image of the button.
Hope it will help someone :)

Related

Simple wipe animation for image view

I've scoured the internet and I cannot seem to find any help on this. I want to have an image perform a wipe animation. By that I mean I would like the image itself to fade in from the left to right (not move from left to right, but fade, like reveal itself. I hope that's not a terrible description) I've found material on how to transition the image with a wipe, but it's outdated and I don't want to transition the image, I want to straight up fade it in. If anybody could help me on this I would be incredible grateful. Thank you so much, let me know if I can help clarify anything!
First thing that came to my mind is to have a separate UIImageView, with image something like this: http://www.creativecow.net/articles/ahearn_luke/creating_clouds/images/gradient.jpg (but transparent-to-white).
So - once You want to fade out Your image, You add as a subview a new UIImageView, which has frame like 3 times the width of the original image You want to hide. Once You add it as a subview, visually nothing would change, as the beginning of the hovering UIImageView would be transparent, But then You start animate frame (origin.x) of the hovering UIImageView so that it would be moved to the left side. While this happens, bottom ImageView will be gradually hidden from one side. After animation ends, You remove/hide both UIImageViews.
Not the best solution, but - if You are stuck, and still want the effect... Atleast some option.. Good luck!

UIButtons titleLabel clips Text after being rotated by CGAffineTransformMakeRotate()

I am developing a iOS-6 app. I have a UIViewController with a view that needs fixed orientation (portrait mode). But when the phone is rotated, one control on that view needs to be moved and rotated (so that it will always be in the upper left corner, and its text will be readable).
I am achieving this by shifting the control(a UIView) using the frame-property of my control (it is a custom view, more on that later), and then using CGAffineTRansformMakeRotate() afterwards, since I know that it's not advisable to use the frame after rotating a view. Everything is fine so far, but here's the thing: That custom view has three UIButtons of type UIButtonTypeCustom as its subviews. Because I rotated the View, but cannot rotate the buttons inside the view (they are not squares), I need to rotate the titleLabels of the Buttons for the text to be readable in the new deviceOrientation.
But it won't work very well. The text will be rotated, as I intended, but it will be clipped by the titleLabel, because the titleLabel has the wrong frame. I checked this by applying borders to the label. So I need to change the titleLabels frame, right? But how can I do that? I tried setting it using [titleLabel setFrame: frameThatFits];, but to no avail. (frameThatFits is a CGRect I created). Also, calling [button.titleLabel sizeToFit]; has no effect that I could see.
I am using [button setTitle:title forControlState: UIControlStateNormal];to set the title.
TL;DR: I'm trying to change the frame/bounds of a UIButtons titleLabel after rotating it using an affine transformation. Any help?
Thanks.
PS: I can supply code when needed, but I wouldn't know what to show you. Tell me what you need, I'll post it.
OK, first of all, thanks to everyone who tried to help. Im posting an alternative solution for my problem, and although it doesnt really address the problem of changing the titleLabels dimensions, it will result in the proper display of my ViewController.
It turns out using the frame is a bad idea. I initially used the frame to reposition the view and i figured that this couldnt be a problem because i only ever applied transformations afterwards, but i was wrong. Because OBVIOUSLY i tried to change the titleLabels frame. AFTER the rotation. And that didnt work.
So the way to go here is using the center-property and the bouds of the view consistently throughout the code. It will result in properly rotated Buttons, that do not need any fidgeting afterwards.
My takeaway here is that i will never ever again use the frame-property outside of a NSLog-statement. But why [button sizeToFit];wouldnt yield any results is still beyond me. If i ever figure it out, i might post it if i remember.
EDIT:
#ZevEisenberg nailed it with this comment:
“Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.” So you are right to use the center and bounds here, but if you do not have a transform, the frame is perfectly safe to use.
NEXT EDIT:
Heres how i ended up repositioning the Buttons:
-(CGPoint)centerForView:(UIView *)view{
//calculate a suitableposition for the view
//depending on the current orientation and the device type (iphone 4S/5, etc)
return point;
}
Then, as a reaction to the deviceOrientation change notification, i apply CGAffineTransformIdentity to all the views, reposition them using my centerForView shown above, and apply the correct rotation transformation to the View. I do this for all the subviews every time the divice rotates, like so:
-(void)setRightRotationTransformations{
[self resetAllTransformations];
self.someSubview.transform = CGAffineTransformRotate(self.someSubview.transform, -M_PI_2);
}
In my case works such hack:
set Line Break mode to Word Wrap
Add extra line to title (even for one line title)

UIView with button below

My question is easy with this drawing :
I have a view above the blue stroke. We can see the buttons behind because this UIView background image is transparent at the left of the button.
My problem is that buttons, behind the views are not clickable.
Is there a way to make them clickable (without playing with adding or removing the view above) ?
Thanks !
Regards,
Sébastien ;)
try to set the
[viewAboveTheBlueStroke setUserInteractionEnabled:false];
because normally the UIView steals the event handling from the other views what it covers (i.e your buttons) and it won't pass them after.
Your image link is broken.
However, you could set the buttonType of your UIBUtton to UIButtonTypeCustom
and then bring them to front:
[self.view bringSubViewToFron:myBut];
You could also consider add UIGestureRecognizers to your image in front instead.

PopOut a middle Image in a UIScrollView contain many images

I have problem in playing with the UIScrollView i am using a customImage Object class to display images on scroll view and event fire on each image i achived it all but i have to do a extra work on it as the giving image showing that the middle image is pop out and fire event for that popout image...
i am confuse in it can anyone tell me how to achive this ....
please told me some steps to start with it..
You should be implementing the UIScrollViewDelegate protocol in the controller which should be handling the UIScrollView.
In there you will get a plethora of delegate callbacks such as when the scrollView moves or is decelerating towards a complete stop etc.
"UIScrollViewDelegate iOS reference"
You can implement any of the methods to suit your exact needs and modify the image's properties. To find which image is in the middle you would be comparing the contentOffset property of the scroll view o image locations.

UIScrollView with "Layers"

Sorry about the title, but I don't know how to say what I want.
I want a UIScrollView with layers, like a image and a text above it, and when it is scrolled, the text is moved faster than the image. Like this video, exactly at 0:13; I've thought about a UIScrollView inside a UIScrollView, but would not be something really good.
Thanks for the attention,
Alberto
You could place an instance of UIImageView behind your UIScrollView. When the method scrollViewDidScroll is called, you can easily change the position of your background view dependent on the offset of the scrollView.