UIView in UITableView disappear when becomes firstResponder - objective-c

In storyboard I have a UITableViewController-->UITableView-->UITableViewSecion--> with static cells
in the same UITableView I also have a UIView that holds a background image and UITextView.
A click on a button shows the UIView and set it's frame, which appears OK, but as soon as I click on the UITextView or make it firstResponder programmatically the keyboard appears and the view disappears
the code when clicking the button
self.myView.frame = CGRectMake(0, self.tableView.contentOffset.y+100, self.tableView.frame.size.width, self.tableView.frame.size.height-100);
self.myView.hidden = NO;
how can I fix this?

Can you copy paste us the code where you add the view to the tableview? Are you doing it with constraints or with frames?
The issue you are having is probably due to the fact the UITableViewControllers automatically shrink the contentSize of the UITableView they hold when the keyboard shows. If you add a UIView to your tableView with addSubview: programmatically, you might need to add a flexible bottom resize mask to make sure when the contentSize shrinks in height, your view stays attached to the top and not the bottom.
Try this on viewDidLoad:
[theViewYouAddedToTableView setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin];

Related

How to generate a image of uiscrollview?

I have a UIScrollView with subview like UILable and webviews. So when I click on a button all the content of the scrollveiw should generate as a image. I tried to generate it but it is not getting all the content of UIScrollView it is just showing only visible view.
and my code is
[Scroll.layer renderInContext:UIGraphicsGetCurrentContext()];
It is because your scrollView's contentSize is larger but its scrollView.frame is still smaller.
Instead of scrollview, add your content first into a UIView (Let say it containerView). containerView should have height-width stretchable according to your content.
After that add your containerView to scrollView. So your scrollView require contentSize = containerView.frame.size
Now try to taking screenshot for the IBOutlet of containerView, not the scrollView.
I have not tried this out, but I guess it should work in this case.

Added UIImageView to UITableViewCell outside cell's bounds

I'm adding an UIImageView to my custom UITableViewCell. This image is then displayed outside the bounds of the cell. I've also added a UITapGestureRecognizer to the image so that when I tap on the image it will be removed from the view.
However when I tap on the image there is another cell beneath it that instead reacts on the tap. So it seems that adding a tap gesture recognizer to the image doesn't have any effect. And yes I have set userInteractionEnabled to YES for the image.
"This image is then displayed outside the bounds of the cell." your view will not receive touches outside it's bounds therefore the subview will not receive touches if it's parent does not

Move UIScrollView so UIButton is fully shown

I have 6 UIButton controls placed inside a UIScrollView.
The buttons are horizontally aligned, but there is only room for 3.5 of them to be visible at a time.
What I want to happen is when I touch the half visible button - for the UIScrollView to move its content so that the touched button will be fully visible (like how the filters bar works in Instagram).
- (IBAction)buttonPressed:(id)sender{
[scrollView scrollRectToVisible:sender.frame animated:YES];
//your code
}
Add action to button.

making buttons change size along when zoom

I have a UIScrollView, with a UIImageView and UIButton inside of it.
I was reading in the answers here that if I have a single view that contains all of my zoomable content, then I should be fine. The problem is that the button doesn't zoom when the image does.
I thought that what I have would work, since the Scroll View is the zoomable view.
Do I need to create another UIView and put everything in there (and keep the same hierarchy?) ?
Have you checked your Springs and Struts? Look in the size inspector under "autosizing". Those little red lines.. if that doesn't make sense, search for 'auto layout'.
I ended up fixing this by declaring the button in code, and added a UView into the hiearchy. The uiview is a subview of the scroll view, and the imageview is a subview of the uiview. I then added the buttons to the uiview.
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
...
[view addSubview:button];

Rotating UITabBarController Icon

I have an UITabBar in my application. One of the tab bar icons looks like a loading symbol. When the user presses the loading button I want the icon to spin/rotate until the loading is done. Should I use UIImageView to animate or something else? How should I make this happen?
Jacos, unfortunately you cannot do that with the UITabBarController and manipulate the tabBarController's tabBar properties. My best bet would be that you use a UIToolBar and assign a black color and make it appear like a tabBar and have buttons added in them as a subView so that they look like tabBarItems.
Its much more customizable, and you can even provide a scrolling experience and add more buttons to it.
I know this question is 4 years old but I had the same problem and managed to fix it by reading the tutorial in here:
https://medium.com/#werry_paxman/bring-your-uitabbar-to-life-animating-uitabbaritem-images-with-swift-and-coregraphics-d3be75eb8d4d#.bjfpbdnut
The main point is to get the view for desired UITabBarItem and the get the UIImageView from it in viewDidLoad:
UIView *plusView = self.tabBar.subviews[1];
self.plusImageView = plusView.subviews.firstObject;
self.plusImageView.contentMode = UIViewContentModeCenter;
Then in didSelectItem method you can do this:
[UIView animateWithDuration:0.4 animations:^{
[self.plusImageView setTransform:CGAffineTransformMakeRotation(M_PI/4)];
}];
My code only rotate the image view for 45 degrees but you can change as you wish.
I guess you could change the UITabBarItem's icon on a timer, but that seems pretty kludgey. You would have to pre-render each frame of your "loading" icon rather than rotate an ImageView.
Another hackey solution would be to add your ImageView to the UIWindow and move it on top of the TabBarController's TabBar (adding it to the TabBar itself is asking for trouble).
You shouldn't try to animate the actual UIImageView within the UITabBarController. I would take this approach:
Set the image for the relevant tab to nil or a blank image.
Create a UIActivityIndicatorView and add it over the tab bar. Position it over the correct tab.
[self.tabBarController.tabBar addSubview:activityIndicatorView];
When your loading task has completed, restore the normal image to the tab and remove the activityIndicator from the tab bar.