Remove Object out of subview - ios

Hey guys I added a UIImageView to the subview and want to remove it after a couple of seconds.
self.view.addSubview(car)
Now I want to remove the image completely. I tried something like:
self.view.delete(car)
But than I get a really long error when I press the button, which should remove the image.
I hope you can help me out.
-Lukas

removeFromSuperview is your way to go.
car.removeFromSuperview()
Methods to manage the view hierarchy are documented for UIView.

Related

Can you help me adding a lottie to a UIButton?

I need help with adding a lottie animationView to a UIButton,
something like this -
just ignore the hebrew text
I need the icon on the right here to be a lottie animation view.. Can't figure it out, don't know if it's at all possible, can someone try to help here?
I need the icon on the right here to be a lottie animation view..
First off, welcome to Stackoverflow.
Secondly, this shouldn't be that hard. Since the goal is to simply make the icon as a lottie animation view, you can either:
Subclass the UIButton - in this way you can put the animation view on top of the imageView of the button.
Add directly a lottie animation view on top of the button.
Personally, I think the first one should do the job and is actually a better method.

Highlight UIButton when not selecting the button itself

I have a custom class here that consists of a UIButton inside of a UIView.
The goal of this class is to allow users to have a greater area (being the UIView) to select the button than just the buttons frame itself.
Now when a user taps on the view I want the buttons highlighted image to show... But the problem is, it does not.
I've read many possible solutions to this issue For Example:
Calling: [btnObject sendActionsForControlEvents:UIControlEventTouchUpInside]
This however did not change the buttons highlight.
I also tried just settings the button.highlighted = YES;
But that did not work either.
I have the images for different states properly setup (Normal and Highlighted), I'm sure of that.
I also have the gestureRecognizer working properly as the functionality is great except for the lack of highlight.
Does anybody know if I'm missing any thing special that needs to be done in order to pull off this seemingly very simple task? Surely it's been done many times.
Thank you
You were on the right track. -[UIButton setHighlighted:] is just a flag. What you need to do is call setNeedsDisplay on that button right after you change the highlighted property.
I solved my problem a little while ago and I'm not sure if Kevin Low's answer would've worked too, it very well might have.
But for some reason, a UITapGesture doesn't work well with highlighting buttons as a view transitions (That might be because I didn't call setNeedsDisplay). The gesture that ended up working was the UILongPressGesture with a 0.0 sec for minimum duration.

How to make SWTableViewCell swipe more sticky

I've implemented the SWTableViewCell code in order to allow side swipes to reveal more UI, such as buttons.
Which is working fine, except that the UIScrollview it subclasses is really just too touchy, flicking back and forth like a manic game of ping pong.
I went to make changes to the class, but realised UIScrollView didn't seem to give me the ability to say change the way the scrolling animations work in the way I wanted.
Leaving me thinking that I either need to create my own version of the a Swipe cell, with a pan gesture and a overlay view, instead of a scrollview or find someone who has already solved this problem.
Please check it out sample: https://github.com/runmad/RMSwipeTableViewCell
May be it will helpful to you, Sir
:)
Not sure if this will give you the effect you desire, but you can make it less "jumpy" by altering the decelerationRate. Try:
someScrollView.decelerationRate = UIScrollViewDecelerationRateFast;
If that's the right idea, you can jump-to-definition in Xcode, and checkout the float value, then try your own.

UIView with UIButtons not showing up prior to click or rotate

I've been banging my head with this issue for the last two days. Googled a lot but wasn't able to find the answer yet, so I decided to request some help here. Let's see if I get any luck.
I'm coding a reusable control that consists of an UIView with a variable number of customized UIButtons. I implemented initWithFrame:, initWithCoder: and drawRect: where the buttons (which are built prior to drawing) are actually added to the view. Everything is done programmatically since the UIButton content should be supplied when using the control, so there's no XIB for this UIView.
This UIView, let's call it CustomizableBarButton is then used in an UIViewController, let's call it MyTestViewController with a view on it, let's call it customizableBarButtonView.
MyTestViewController's GUI was set on IB where an UIView was tied to customizableBarButtonView (the class was matching accordingly).
MyTestViewController's is a pretty standard class except for the viewWillAppear: that initializes the buttons and passes them to the CustomizableBarButton along with some other options.
The issue is that everything works perfectly...except for the first time!
I mean, when I run the app on the simulator (I haven't tried it on the iPhone yet but I strongly believe that it's not an hardware issue) the MyTestViewController shows the customizableBarButtonView background but not the buttons. Now when you click on the place where a button should be all the buttons suddenly appear!
I'm puzzled since the CustomizablebarButton drawRect: runs before the strange "click n'appear" effect and the buttons are actually added to the subview.
Another hint that my help: if you don't click on the buttons (so you still got no buttons yet) but rotate the device they will also appear as if by magic!
It is probably something very simple but I'm missing it and I'm going nuts...
Can someone lend a hand on this, please?
Thanks in advance!
You said you're adding the buttons in drawRect:. Don't do that. You need to add the buttons in your init methods.

add UIPanGestureRecognizer to a UIView

I have 2 UIViews; let's call'em mainView and otherView. mainView uses the whole screen (it is an iPad app) and otherView is a smaller one that appears on top of mainView. The problem is that I don't know how and where to add the UIPanGestureRecognizer. The code snippets I find shows the code, but its never clear (or I'm not sure why it never works).
Most of the time I get a "otherView may not respond to +addGestureRecognizer" warning, I've tried adding the UIGestureRecognixerDelegate in practically all headers file and I don't know what I'm doing wrong.
Hope you can help me out :)
addGestureRecognizer is not a class method, it's an instance method. Other than that, without code there's not much I can say.
Also, check out CS193P Lecture 8: Gesture Recognizers. iTunes Link

Resources