Toggling UITableViewCell selectionStyle causes labels on cell to disappear - ios

I have a custom subclass of UITableViewCell. On my storyboard, it basically has a containerView (UIView *), that has some labels on it, and a UISwitch. I add a gesture to slide my tableViewCell to the right to show some detail controls underneath the containerView, and then another gesture to slide the original view back. The animation code looks like this:
- (void)showCustomControls:(UISwipeGestureRecognizer *)gesture {
[UIView animateWithDuration:0.3 animations:^{
[self.containerView setFrame:CGRectMake(self.frame.size.width - kTableViewCellSwipedWidth, 0, self.frame.size.width - kTableViewCellSwipedWidth, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
self.isReveal = YES;
self.selectionStyle = UITableViewCellEditingStyleNone;
}];
}
- (void)hideCustomControls:(UISwipeGestureRecognizer *)gesture {
[UIView animateWithDuration:0.3 animations:^{
[self.containerView setFrame:CGRectMake(-kTableViewCellBounceWidth, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.1 animations:^{
[self.containerView setFrame:CGRectMake(-kTableViewCellBounceWidth / 2, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}completion:^(BOOL finished) {
[self.containerView setFrame:CGRectMake(0, 0, self.frame.size.width, kOverviewTableViewCellHeight)];
}];
self.isReveal = NO;
self.selectionStyle = UITableViewCellSelectionStyleBlue;
}];
}
I noticed if I left the selectionStyle on, with the row open, it looked kind of funny. So I wanted to turn the selectionstyle off. So the code in there is to turn on and off the selection style when the row is open or closed. It works, however the weird thing is, when hideCustomControls gets called, and my original row slides back into place, the labels on the container view all go away. I have a little edge of the original row that shows, and when that is showing, the labels are there. But the second that the row slides all the way in place, all the labels disappear. The UISwitch which is also on the containerView never has problems though. It is always present. Is there a reason why this may be happening? When I remove the selectionStyle code in both methods, this problem goes away. Thanks in advance.
Edit:
I put in the correct code to animate using NSLayoutConstraint. Now the problem is the UIView subclasses I have on the view underneath show through to the top view when my row slides back into place. Not sure why this happens...

Related

Showing UIPickerView when cell is selected

For my app I’m implementing in-app settings using tableView with Dynamic prototype cells. Inside cell I’m showing main title and sub title. What I would like to achieve is when user clicks on one of the cells (that represents specific settings) the pickerView will slide from the bottom of the screen showing the options that user can pick. I’ve seen few tutorials where this pickerView is presented inside a cell as it is e.g. in iOS calendar app but I don’t need that – all will be fine if it will slide from the bottom actually in a same way as it is when you are having pickerView as inputView for your text field (e.g. textField.inputView = pickerView) and click to the text field. I appreciate any help you can provide guys! Thanks in advance!
You can create a custom view xib in which you can have pickerView,when user click on cell just show the custom view with animation.
viewPicker = CGRectMake(0, 490, 320, 460);
For the animation from bottom to top add below:
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 0, 320, 460);
}
completion:^(BOOL finished){
}];
[self.view addSubview:viewPicker];
For removing the view
[UIView animateWithDuration:1.5
delay:0.5
options: UIViewAnimationCurveEaseIn
animations:^{
viewPicker.frame = CGRectMake(0, 490, 320, 460);
}
completion:^(BOOL finished){
if (finished)
[viewPicker removeFromSuperview];
}];

Hidding view with table scroll

I'm searching for idea how to implement a table view with moving view on top of it.
So the idea is something similar to navBar in facebook app. When you scroll up this (red) view is moving up and hiding, when you scroll up its going up and when you scroll down its revealed. This is not nav bar so most of the pods I've found are not working in this situation. This cannot be tableView header or section header as well.
You need added this view above table:
[self.tableView.superview insertSubview:view aboveSubview:self.tableView]
Or you can do it in storyboard.
When you table scroll down hide view, when up show.
[view setHidden:YES];
Also u could change table inset to the top of the superview.
self.tableView.contentInset = self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(self.tableView.contentInset.top -, self.tableView.contentInset.left, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
I think fast way to do it use gesture recognizers to recognize reveal and hide actions and than you can use methods like below,
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:0.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
and for reveal attached view
[UIView animateWithDuration:0.5 animations:^{
[attachedView setAlpha:1.0f];
} completion:^(BOOL finished) {
[attachedView setHidden:YES];
}];
methods will help you to hide and reveal views gently.
Take a look at this library, it does exactly what you want to do
https://github.com/telly/TLYShyNavBar

Custom UIActivityViewController-like view that slides up and down

Is there a way to subclass or customize UIActivityViewController to create a sort of custom view? For example, see the image below from the app Overcast. I want to create a view similar to that, where if you tap a button, the view pops up and when you tap outside of the view, it slides back down.
Why not use an UIView ? Set it's initial frame's y value to -self.customView.frame.size.height and animate it's frame to the normal position using [UIView animateWithDuration]
-(void)showCustomView{
[self.customview setFrame:CGRectMake(0, -self.customView.frame.size.height, self.view.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.bounds.size.height-self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
-(void)hideCustomView{
[UIView animateWithDuration:0.25 animations:^{
[self.customView setFrame:CGRectMake(0, -self.customView.frame.size.height, self.customView.bounds.size.height+self.customView.frame.size.width, self.customView.frame.size.height)];
}];
}
Add an UITapGestureRecognizer and call hideCustomView when tapped outside the customView

How to remove delete button when editing UITableViewCell?

I want to customize my cell behavior - I want cell view to change and different buttons appear. I got half of it working - when I swipe I get the view to move.
But I have this delete button to the right side of cell, I want to get rid of it and use custom button instead of it. What should I use to remove it and where do I bind my button to do the same thing?
I tried using two methods, setEditing: and willTransitionToState, but that didn't help.
If I skip calling parent method in any of these, I don't get delete button as I want, but my view never returns to its original position after editing and other cells stop reacting to swipes. What do I need to do to fix this?
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:YES];
if (editing) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100, 0);
}];
} else {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformIdentity;
}];
}
}
-(void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if (state == UITableViewCellStateShowingDeleteConfirmationMask) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100, 0);
}];
}
if (state == UITableViewCellStateDefaultMask) {
[UIView animateWithDuration:0.3 animations:^{
self.parentView.transform = CGAffineTransformIdentity;
}];
}
}
Since your cell is a subclass of UITableViewCell, and you don't want to use the stock delete you probably want to disable it. The bare basic way would be to return no editing style for any of the cells.
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
Some of the comments mentioned what you can do next.
Add an additional view that is below the main view of your cell.
Add a button on that view on the right in the same place the delete button was.
Use either a swipe gesture recognizer to do a basic swipe or a pan gesture recognizer
for dragging (normal behavior).
Update the top view frame based on the translations.
no you can't change the delete button that appears in default UITableViewCell.
Instead, create a customClass of UITableViewCell.
or,
Hack its subView and find any subView which is of class UIButton and title text "delete", then change it.

Animating two UIView subviews at the same time does not work

For some reason i am not able two animate two subviews postion. I have wrote the following
[self addChildViewController:self.photosViewController];
[self.photosViewController.view setFrame:CGRectMake(0, -self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:self.photosViewController.view];
[UIView animateWithDuration:1 delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[self.stepsView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
[self.photosViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
completion:^(BOOL finished) {
if (finished) {
button.tag = 0;
}
}];
self.stepsView is an IBOutlet UIView and self.photosViewController.view is an child view controllers view that has been added to the view.
With the current code only the self.PhotosViewController.view animates. However if i comment out the line where i add the child view controllers view as a subview then the self.stepsView animates correctly.
Even if i add the child view controller and its view before this method is called the same error happens.
Need help as i ran in to this a couple of months back with another app and had to do a dirty hack to get around it and now want to solve this.
Thanks
In the section on view animation in the View Programming Guide there is a specific mention of how to animate subviews.
Basically, you should use transitionWithView:duration:options:animations:completion: rather than animateWithDuration:delay:options:animations:completion:.
The first view will not be visible, because its origin.y is beyond the height of the visible view. If it was not visible when the animation starts, you will of course see nothing.
The second view is changed to fill the screen. Again, what you see depends on its initial position.

Resources