I'm calling a view controller from my mainScreen with the following code:
VisualizarFotoViewController *visualizarFoto = [self.storyboard instantiateViewControllerWithIdentifier:#"VisualizarFoto"];
[self presentViewController:visualizarFoto animated:NO completion:^{
[UIImageView animateWithDuration:0.5 animations:^{
visualizarFoto.visualizarFoto.contentMode = UIViewContentModeScaleAspectFit;
visualizarFoto.visualizarFoto.image = _fotoPrincipal.image;
visualizarFoto.viewPrincipal.alpha = 1;
visualizarFoto.telaOrigem = 2;
}];
}];
To come back to the mainScreen I dismiss the view controller with the following code:
[UIImageView animateWithDuration:0.2 animations:^{
_viewPrincipal.alpha = 0;
} completion:^(BOOL finished) {
[self dismissViewControllerAnimated:NO completion:nil];
}];
My issue is that when I come back to the mainScreen, my scrollview doesn't answer to any scrolling gesture. I've tried to use [_scrollView becomeFirstResponder] in viewDidAppear section but with no success.
Do you have any hint to solve this please?
Thanks
If is there someone looking for an answer, this is what I did to solve this issue:
- (void)viewDidLayoutSubviews {
// Define the scrollview size accordingly with the number of pages
[_scrollView setFrame:CGRectMake(0, 43, 320, 450)];
[_scrollView setContentSize:CGSizeMake(320 * 3, 450)];
}
Related
In my didSelectRowAtIndexPath method I call [self dismissView]; when the user selects a cell in order to dismiss the view if its already been presented. This clearly isn't very optimal and its overriding the presentView method without it animating the dismissView. Is there a better way to do this? Or at the very least let it wait for the view to finish animating without using NSTimer.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
[self dismissView];
// Do xyz...
[self presentView:twitterLinksView];
Then..
- (void)presentView:(id)sender
{
twitterLinksView.frame = CGRectMake(0, (self.view.frame.size.height + viewHeight), 320, 300);
[UIView animateWithDuration:0.60f animations:^{
CGRect twitterLinkFrame = self.twitterLinksView.frame;
twitterLinkFrame.origin.y = (self.view.frame.size.height - viewHeight);
twitterLinksView.frame = twitterLinkFrame;
}];
}
- (void)dismissView
{
[UIView animateWithDuration:0.75f animations:^{
CGRect twitterLinkFrame = self.twitterLinksView.frame;
twitterLinkFrame.origin.y = (self.view.frame.size.height + viewHeight);
self.twitterLinksView.frame = twitterLinkFrame;
}];
}
[UIView animateWithDuration:1. animations:^{
//firstAnimationBlock
} completion:^(BOOL finished){
[UIView animateWithDuration:1. animations:^{
//animations in this block will be called after firstAnimationBlock has expired
}];
}];
as i understand you wanna fire 2 animation one after the other. this code (block inside block) makes this
this part is after edit:
ok now you can try writing like that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
[self dismissView];
// Do xyz...
[self performSelector:#selector(presentView:) withObject:twitterLinksView afterDelay:0.75];
//[self presentView:twitterLinksView];
}
I ended up splitting out my creation method and using [[self.view subviews] containsObject:twitterLinksView] to check for the view. Also to be noted is [self performSelector:#selector(createView) withObject:twitterLinksView afterDelay:0.76f] had to be very slightly ahead of the dismissing animation for it to work at all... yeah wtf.
In the didSelectRowAtIndexPath method i used [self performSelector:#selector(presentView:)];
Thanks to meth for solving part of the puzzle.
- (void)presentView:(id)sender
{
if ([[self.view subviews] containsObject:twitterLinksView])
{
[self dismissView];
[self performSelector:#selector(createView) withObject:twitterLinksView afterDelay:0.76f];
NSLog(#"Animating ut old");
}
else
{
NSLog(#"Creating new view");
[self createView];
}
}
-(void)createView
{
twitterLinksView.frame = CGRectMake(0, (self.view.frame.size.height + viewHeight), 320, 300);
[UIView animateWithDuration:0.60f animations:^{
CGRect twitterLinkFrame = self.twitterLinksView.frame;
twitterLinkFrame.origin.y = (self.view.frame.size.height - viewHeight);
twitterLinksView.frame = twitterLinkFrame;
[self.view addSubview:twitterLinksView];
}];
}
- (void)dismissView
{
[UIView animateWithDuration:0.75f animations:^{
CGRect twitterLinkFrame = self.twitterLinksView.frame;
twitterLinkFrame.origin.y = (self.view.frame.size.height + viewHeight);
self.twitterLinksView.frame = twitterLinkFrame;
}completion:^(BOOL finished){
[twitterLinksView removeFromSuperview];
}];
}
I have a UIViewController, which on it - I use presentViewController to present a new window:
controller.view.frame = source;
[self presentViewController:controller animated:NO completion:nil];
[UIView animateWithDuration:ANIMATION_NORMAL_DURATION animations:^{
controller.view.frame = target;
}completion:^(BOOL finished) {
}];
When I do that - the parent controller (self) disappears before the new controller (controller) appears. And it makes it ugly.
Is there a better way to implement it?
(I don't use NavigationControler in those ViewContollers)
Thanks.
From iOS7 there is the modalPresentationStyle property.
Set it to one of this options: UIModalPresentationOverFullScreen, UIModalPresentationOverCurrentContext, UIModalPresentationCustom
modalViewController.modalPresentationStyle = UIModalPresentationCustom;
do not present, just add a subview
controller.view.frame = source;
//[self presentViewController:controller animated:NO completion:nil];
[self.view addSubview:controller.view];
[UIView animateWithDuration:ANIMATION_NORMAL_DURATION animations:^{
controller.view.frame = target;
}completion:^(BOOL finished) {
}];
In my iPhone App I need to display a modal view with transparent background and it should appear with animation like it is appearing from center of view and its size is increasing.
similar like "drawing something" iPhone App when we click on settings button.
How do I do this?
You can do one of 4 following transition styles:
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:viewController animated:YES];
If you want something that is not included in these defaults you are going to have to build your own custom animation for presenting the modal view. Like the following but obviously for the style you want.
UIModalTransitionStyle horizontal movement
Let's say you have a viewController thats called aScoreSheet that you want to present. Try to define this method in the view controller that's going to do the presenting.
-(void) presentTransparentModalViewController: (ScoreSheet *) aViewController
{
scoreSheet = aViewController;
UIView *view = aViewController.view;
view.opaque = NO;
[view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *each = obj;
each.opaque = NO;
}];
[self.view addSubview:view];
view.center = CGPointMake(160, 800); //for iPhone
[UIView animateWithDuration:0.9 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
view.center = CGPointMake(160, 240);
} completion:^(BOOL finished) {
self.view.userInteractionEnabled=YES;
}];
}
and then to dismiss the controller:
-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{
if (animated) {
[UIView animateWithDuration:0.4
animations:^{
scoreSheet.view.center = CGPointMake(scoreSheet.view.center.x, scoreSheet.view.center.y + 480);
} completion:^(BOOL finished) {
[scoreSheet.view removeFromSuperview];
scoreSheet = nil;
}];
}
}
Not a full answer, but maybe you can take a look at this open source library:
https://github.com/Split82/HMGLTransitions
It has some custom modal transitions, maybe not exactly the one you are looking for, but you can easily add your transition by subclassing HMGLTransition.
Hope this helps
I have paging UIScrollView with images. I want to implement animated zooming of image to fullscreen on some gesture. And another animation to zoom image back to scroll view. Like in Photos app on iPad or like videos in Safari.
Of course it would not be UIImageView. It would be some wrapper class with image inside. The main question is how to present fullscreen view. Is it must be modal view or not.
Any help is appreciated.
Check on touching the image
if it is small convert into full size.
if it is large convert into small size.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if (isLarge) [self makeSmall];
else [self makeFull];
}
- (void)makeFull {
[[self superview] bringSubviewToFront:self];
isLarge = YES;
CGRect largeFrame = [self superview].bounds;
original = self.frame;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setFrame:largeFrame];
[internal setFrame:self.bounds];
[UIView commitAnimations];
}
- (void)makeSmall {
isLarge = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self setFrame:original];
[internal setFrame:self.bounds];
[UIView commitAnimations];
}
I found a solution to this that involves both gesture recognizers and animated transitions. You remove the scrollview and add the fullscreen image. Then reverse that to return to the just the scrollview.
Use the frame of the window to determine size for the new UIImage.
The types of gesture recognizers can be adjusted to suit your needs!
-(void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *tapTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapTwice:)];
tapTwice.numberOfTapsRequired = 2;
[self.imageView addGestureRecognizer:tapTwice];
}
- (void)tapOnce:(id)tapOnce {
[UIView transitionWithView:self.view
duration:0.7
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.fullScreenImage removeFromSuperview];
}
completion:nil];
}
- (void)tapTwice:(id)tapTwice {
if(self.fullScreenImage == nil){
self.fullScreenImage = [[UIImageView alloc] initWithFrame:self.view.window.frame];
UITapGestureRecognizer *tapOnce = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapOnce:)];
tapOnce.numberOfTapsRequired = 1;
[tapOnce requireGestureRecognizerToFail:tapTwice];
[self.fullScreenImage addGestureRecognizer:tapOnce];
[self.fullScreenImage setUserInteractionEnabled:YES];
//self.fullScreenImage = [load your image here]
}
[UIView transitionWithView:self.view.window
duration:0.7
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
[self.view.window addSubview:self.fullScreenImage];
}
completion:nil];
}
Download this sample for Image gallery sample code and get through it. It would definitely helps you to understand how to implement your idea.
Like below you can use for zooming the image view.
UIView * viewForScroll;
UIImageView *imgviewForScroll;
UIScrollView *scrollToRead = [[UIScrollViewalloc]initWithFrame:CGRectMake(175, 5, 300, 311)];
scrollToRead.backgroundColor = [UIColordarkGrayColor];
scrollToRead.showsHorizontalScrollIndicator = YES;
scrollToRead.delegate = self;
[scrollToRead setContentSize:CGRectMake(0, 0, 300, 400).size];
scrollToRead.maximumZoomScale = 2;
scrollToRead.minimumZoomScale = 1;
[self.view addSubview:scrollToRead];
[scrollToRead release];
viewForScroll = [[UIViewalloc]initWithFrame:CGRectMake(0,0,300,400)];
[scrollToRead addSubview:viewForScroll];
[viewForScroll release];
imgviewForScroll = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,300,400)];
imgviewForScroll.image = [UIImageimageWithContentsOfFile:[arrayComicContentobjectAtIndex:0]];
[viewForScroll addSubview:imgviewForScroll];
[imgviewForScroll release];
//=========UIScrollView Delegate methods
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return viewForScroll;
}
Like to know if you need any further clarifications
As suggested by this popular answer, I am using blocks for animating views as per the code:
UIView *whiteout = [[UIView alloc] initWithFrame:self.view.frame];
whiteout.backgroundColor = [UIColor blackColor];
[self.view addSubview:whiteout];
[UIView transitionWithView:self.view duration:2.0 options:UIViewAnimationTransitionFlipFromRight animations:^{ [whiteout removeFromSuperview]; } completion:nil];
However the animation does not happen and the whiteout view is removed immediately. What am i missing here??
Removing from a superview is not animatable. If you want to fade out your view, try setting its alpha to 0, then remove it on completion:
[UIView transitionWithView:self.view duration:2.0 options:UIViewAnimationTransitionFlipFromRight animations:^{
whiteout.alpha = 0.0;
} completion:^(BOOL completion){
[whiteout removeFromSuperview];
}];