How to put UICollectionView and button in UIPageControl in ios? - ios

This is my collectionview when i swipe it scrolls,
i have putted UICollectionView and button in UIPageControl, when swipe UICollectionView scrolling, and button view not scrolling smoothly as works as normal UIPageControl

I'm not sure but I think it has something to do with your CATransitions
Try changing the last piece of the method so you use UIView animations instead of CATransitions:
if(pageControl.currentPage==pageControl.numberOfPages-1)
{
[UIView animateWithDuration:0.2
animations:^{
dayRadialCollection.alpha = 0.0f;
addWeek.alpha = 1.0f;
removeWeek.alpha = 1.0f;
} completion:^(BOOL finished) {
}];
}
else {
[UIView animateWithDuration:0.2
animations:^{
dayRadialCollection.alpha = 1.0f;
addWeek.alpha = 0.0f;
removeWeek.alpha = 0.0f;
} completion:^(BOOL finished) {
}];
}
There is also no need to hide the elements, as alpha 0.0f will not show them anyway.

Related

Hiding and showing UITableview with slide down and slide up animation

is it possible to put animation to UITableView?
I currently have this:
- (IBAction)mPesoAccount:(id)sender {
if (accountBalanceTableView.isHidden) {
accountBalanceTableView.hidden = NO;
} else {
accountBalanceTableView.hidden = YES;
}
}
it hides or show the uitableview whenever i click a button, i would like to add an animation when i'm hiding and showing the uitableview
it would similar like a dropdown item, where it slides up into the button and collapses down when the button clicked again.
Simply animating your UITableView frame if you are using non constraints approach, or making the bottom constraint IBOutlet and changing the constant value
- (void)viewDidLayoutSubViews
{
[super viewDidLayoutSubViews];
self.originalTableViewFrame = accountBalanceTableView.frame;
}
- (IBAction)mPesoAccount:(id)sender {
if (accountBalanceTableView.isHidden)
{
[UIView animateWithDuration:.3 animations:^{
accountBalanceTableView.frame = self.originalTableViewFrame;
}completion:^(BOOL finished) {
accountBalanceTableView.hidden = NO;
}];
}
else
{
[UIView animateWithDuration:0.3 animations:^{
accountBalanceTableView.frame = CGRectMake(originalTableViewFrame.origin.x, originalTableViewFrame.origin.y + originalTableViewFrame.size.height, originalTableViewFrame.size.width, 0);
} completion:^(BOOL finished) {
accountBalanceTableView.hidden = YES;
}];
}
}

Pop up Views in ios

I have a location button. I want to open a pop up view when location button got pressed. like this
when this view opened, all buttons and background view should be blurred.
How can i achieve this??
thnx for any kind of help.
To show the view with alert like animation create a popView you want to show and follow the below code:
popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[self.view addSubview:popView];
[UIView animateWithDuration:0.3/1.5 animations:^{
popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
popView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
popView.transform = CGAffineTransformIdentity;
}];
}];
}];
popView.transform = CGAffineTransformIdentity;
Hide the other views visible.
Just follow the below code
-(IBAction)buttonPress:(id)sender
{
popView.hidden = NO;
//OR
[self.view addSubview:popView];
btn1.hidden = YES;
btn2.hidden = YES;
btn3.hidden = YES;
view1.hidden = YES;
}
Simple,
Create one view & size of that view will be size of parent view. Your second view will contain your UI along with black blur view at background.
When you tap on the location button display that view so all other button will be hidden automatically.

How to animate deletion of a label?

I have a view controller that have a scroll view that bounce horizontally , and in this scroll view I have a label.
I can now hold the label and scroll it down, and if I release it will bounce up back.
What I want is that: When I scroll the view y coordinate (using myScrollView.contentOffset.y) to some value, lets say -33 and under I can release my fine and the label will animate to the bottom of the screen and disappear, and now I can set the label to be a new value, and It will animate from top to the label original position.
Here a photo of how the view controller looks like:
And this is the relevant method I already implemented (powered by #rebello95):
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.myScrollView.contentOffset.y <= -73) {
[UIView animateWithDuration:0.3 animations:^{
self.homeLabel.alpha = 0.0;
} completion:^(BOOL finished) {
[self.homeLabel removeFromSuperview];
self.homeLabel = nil;
}];
}
NSLog(#"%f", self.myScrollView.contentOffset.y);
}
Now I want it to slide to the bottom of the page and fade.
thanks!
EDIT: The animation now moves the label to the bottom of the view controller then fades it out.
You can use an animation block to move the label, then put another block inside the completion block to fade out the label, then remove it after the animation completes.
Example:
[UIView animateWithDuration:0.3 animations:^{
[self.myLabel setFrame:CGRectMake(self.myLabel.frame.origin.x, self.view.frame.size.height - self.myLabel.frame.size.height, self.myLabel.frame.size.width, self.myLabel.frame.size.height)];
self.labelRemoving = YES;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
[self.myLabel removeFromSuperview];
self.myLabel = nil;
self.labelRemoving = NO;
}];
}];
Sidenote: You should probably be using <= instead of == in your if statement to achieve your desired results. In addition, you may want to set a flag to indicate that your label is being removed (since that method will inevitably be called multiple times). Something like this:
//.h
#property (nonatomic, assign) BOOL labelRemoving;
//.m
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (self.myScrollView.contentOffset.y <= -33 && !self.labelRemoving) {
[UIView animateWithDuration:0.3 animations:^{
[self.myLabel setFrame:CGRectMake(self.myLabel.frame.origin.x, self.view.frame.size.height - self.myLabel.frame.size.height, self.myLabel.frame.size.width, self.myLabel.frame.size.height)];
self.labelRemoving = YES;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
self.myLabel.alpha = 0.0;
} completion:^(BOOL finished) {
[self.myLabel removeFromSuperview];
self.myLabel = nil;
self.labelRemoving = NO;
}];
}];
}
NSLog(#"%f", self.myScrollView.contentOffset.y);
}

UISegementedControl reverts back to original frame after touch

Every time I click on my UISegementedControl it snaps back to its original frame. I can see it barely through my translucent toolbar.
I have a UIViewController with a UITableView, and UIToolBar like this:
There is a UISegmentedControl hidden just below the table view, behind the toolbar:
The Filter button calls the 'onFilterButtonPressed' method
- (IBAction)onFilterButtonPressed:(id)sender
{
if(self.filterBar.hidden){
[self showFilterBar];
} else {
[self hideFilterBar];
}
}
- (void)hideFilterBar
{
CGRect filterBarFrame = CGRectMake(0, self.view.frame.size.height+(self.filterBar.frame.size.height+1), self.filterBar.frame.size.width, self.filterBar.frame.size.height);
CGRect tableViewFrame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y,self.tableView.frame.size.width, self.tableView.frame.size.height+(self.filterBar.frame.size.height+1));
[UIView animateWithDuration:0.3 animations:^{
[self.filterBar setFrame:filterBarFrame];
[self.tableView setFrame:tableViewFrame];
} completion:^(BOOL finished) {
self.filterBar.hidden = YES;
}];
}
- (void)showFilterBar
{
CGRect filterBarFrame = CGRectMake(0, self.view.frame.size.height-(self.filterBar.frame.size.height+1), self.filterBar.frame.size.width, self.filterBar.frame.size.height);
CGRect tableViewFrame = CGRectMake(self.tableView.frame.origin.x, self.tableView.frame.origin.y,self.tableView.frame.size.width, self.tableView.frame.size.height-(self.filterBar.frame.size.height+1));
self.filterBar.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
[self.tableView setFrame:tableViewFrame];
[self.filterBar setFrame:filterBarFrame];
}];
}
This is because of auto layout. With that turned on (which it is by default), you should do any positioning or resizing of views by modifying constraints, not setting frames.

How to check if NSLayoutConstraint is animating

I am creating a custom NSLayoutConstraint subclass and I need to know if the layout constraint's constant property is currently animating for internal state handling. In other words, I need to distinguish between:
{ //no animation
myLayoutConstraint.constant = 100;
}
and
{ //animated
myLayoutConstraint.constant = 100;
[UIView animateWithDuration:0.2 animations:^{
[self.myViewThatHasTheConstraintAttached layoutIfNeeded];
} completion:^(BOOL finished) {
[...]
}];
}
So that I can handle corner cases for receiving a message on the middle of an animation. Is this possible?
The only way to do this would be to have a boolean wherever you want to access this and do something like...
{ //no animation
theView.animatingChange = NO;
myLayoutConstraint.constant = 100;
}
{ //animated
theView.animatingChange = YES;
myLayoutConstraint.constant = 100;
[UIView animateWithDuration:0.2 animations:^{
[self.myViewThatHasTheConstraintAttached layoutIfNeeded];
} completion:^(BOOL finished) {
[...]
theView.animatingChange = NO;
}];
}
The property on the view changes immediately to the "end" value of the animation. It doesn't get changed to all the intermediate values while it is animating. Just the drawing on the screen is animated.

Resources