I am trying to transition from one view to another.
The final view I'm transitioning to is a XIB with a couple buttons and a title bar.
My problem is that after the transition, the buttons get displayed on the very top left of the window for a fraction of a second, and eventually "drag" to their expected coordinates. Everything is perfectly usable and functional, but the transition looks a little funny.
Any idea what could cause this?
Here is my code snipet:
Homepage *hp = [[Homepage alloc] init];
hp.data = self.data;
[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [self.view addSubview:hp.view]; }
completion:nil];
[hp DisplayThumbnails];
[hp release];
I wanted to provide the code snippet that I've used to resolve this problem using Jacob's recommendation in case someone else runs into this. Here it is:
Homepage *hp = [[Homepage alloc] init];
hp.data = self.data;
[hp.view setHidden:YES];
[self.view addSubview:hp.view];
[UIView transitionWithView:self.view duration:0.5
options:UIViewAnimationOptionTransitionCurlDown
animations:^ { [hp.view setHidden:NO];}
completion:nil];
[hp DisplayThumbnails];
Related
I have implemented refreshControl as shown below in viewDidLoad():
refreshControl = [[UIRefreshControl alloc] init];
if (#available(iOS 10.0, *)) {
self.tableView.refreshControl = refreshControl;
} else {
[self.tableView addSubview:refreshControl];
}
Now I am presenting another viewController which has options to select filters. And after selecting those filters you come back again to current viewController having refreshControl.
I have added below code in viewDidAppear() for manually calling beginRefreshing:
if (self.filterChanged) {
self.filterChanged = NO;
[self.activityTableView setContentOffset:CGPointMake(0, - refreshControl.frame.size.height) animated:YES];
[refreshControl setHidden:NO];
[refreshControl beginRefreshing];
}
I have used setContentOffset for scrolling back to top and showing refreshControl.
The only problem is suppose my tableView is half scrolled in between then there is a big gap between refreshControl.
If my tableView is not scrolled then it works fine like I have pulled down to refresh, but if it is half scrolled then inspite of giving setContentOffset there is a big gap between refreshControl and tableview.
You need to wait for the scroll to finish before you can start the refresh. Unfortunately there is no completion block on setContentOffset, so try this.
After creating your refresh control set the target and create a corresponding method.
[_refreshControl addTarget:self action:#selector(refreshRequested) forControlEvents:UIControlEventValueChanged];
- (void)refreshRequested {
[_activityTableView reloadData];
}
In your viewDidAppear you scroll to top and refresh when done.
[UIView animateWithDuration:0.25 delay:0 options:0 animations:^(void){
self.activityTableView.contentOffset = CGPointMake(0, -self.refreshControl.frame.size.height);
} completion:^(BOOL finished){
[self.refreshControl beginRefreshing];
[self refreshRequested];
}];
When finished loading you need to end refresh and make sure to scroll back to zero position.
- (void)finishedLoading {
[_refreshControl endRefreshing];
[self.activityTableView setContentOffset:CGPointMake(0, 0) animated:YES];
}
When I run my app on iOS 7, all iAds works like a charm in every view controllers. But when i run my app on iOS 8 and navigate around the app when i return to main view or maybe in other view before charged, the iAds shows blank. I've tried all types of code, and with all of them have the problem.
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (!_adBanner) {
_adBanner = [[ADBannerView alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 50)];
[_adBanner setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:_adBanner];
}
_adBanner.delegate = self;}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
_adBanner.delegate=nil;
}
//delegates
-(void)bannerViewDidLoadAd:(ADBannerView *)banner{
if (!_bannerIsVisible /*&& _original*/) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[_adBanner setAlpha:1];
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = YES;
}
}
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
if (_bannerIsVisible) {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[_adBanner setAlpha:0];
banner.frame = CGRectOffset(banner.frame, 0, banner.frame.size.height);
[UIView commitAnimations];
_bannerIsVisible = NO;
}
NSLog(#"%#",error);
}
And in console get this error: "Error Domain=ADErrorDomain Code=7 "The operation couldn’t be completed. Ad was unloaded from this banner" UserInfo=0x7a698c20 {ADInternalErrorCode=7, ADInternalErrorDomain=ADErrorDomain, NSLocalizedFailureReason=Ad was unloaded from this banner}"
I am having exactly the same issue and I want to post an answer here which doesn't solve it in my case (so please accept that THIS IS NOT AN ACTUAL answer) but I wanted to provide a few details that I can't do in a comment.
I'm having the exact same issue with switching between views in a UITabBarController and when I come back to the first view, the AdBannerView is there, but doesn't actually show any ads for 1 minute, even though the delegate methods are being run.
I firstly went and followed this guide (https://www.youtube.com/watch?v=_0Mv44FWw0A&feature=youtu.be) on how to set up Shared instances of AdBannerViews which may or may not be what you're doing, but this could help; you never know.
In my case, that didn't do anything.
But I did implement viewWillDisappear:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.adBanner.delegate = nil;
self.adBanner = nil;
[self.adBanner removeFromSuperview];
}
If I comment out that code, I receive the same error you're facing in the console, with Error Code 7. If I don't comment out that code, I get through without any errors (i.e the didFailToReceiveAdWithError never gets run).
However, the issue I'm facing is that when I come back to the view from another tab, the viewWillAppear gets run, followed instantly by the bannerViewDidLoadAd, but that doesn't actually bring in the ad for 1 minute and instead I'm left with a blank white banner.
Also, I'm running the loading code from the viewWillAppear (because this gets called every time you come back to this ViewController, instead of viewDidLoad.
self.adBanner = [[self appdelegate] adBanner];
self.adBanner.delegate = self;
[self.adBanner setFrame:CGRectMake(0, 101, 320, 580)];
[self.view addSubview:self.adBanner];
I'm not sure if this will help. I hope it does and if it does, perhaps we can work together to understand why mine doesn't work on iOS 8, either!
I have no idea, why it is not working.
All I want to do is a simple UIView animation in the viewDidLoad.
Here's my code:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setCenter:CGPointMake(0.0, 200.0)];
}];
Nothing happens. When I test the general approach of calling a animation method on that particular object like this:
[UIView animateWithDuration:3.0f animations:^{
[self.headline setAlpha:0.0];
}];
it works!!! Why am I not able to move the view across the screen? I am using latest Xcode 4.5.
Thanks for any advice!
UPDATE:
When I add a view manually in code it works. But for the UIViews I create as Outlets in the Interface Builder it doesn't work.
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
testLabel.backgroundColor = [UIColor redColor];
[self.view addSubview:testLabel];
[UIView animateWithDuration:3.0 animations:^{
testLabel.center = CGPointMake(0.0, 200);
}];
So obviously I am doing something wrong in the .xib file
Dont do it in viewDidLoad. The view is not pressent at that time yet.
Try it in viewDidAppear.
Well, I think the reason for the missing animation was the fact that I called a different push navigation animation from the view controller that was pushing the actual view on screen:
- (IBAction)goForSelection:(id)sender
{
SelectionViewController *selectionViewController = [[SelectionViewController alloc] initWithNibName:#"SelectionViewController" bundle:nil];
//[self.navigationController pushViewController:selectionViewController animated:YES];
[UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
[self.navigationController pushViewController:selectionViewController animated:NO];
} completion:^(BOOL finished) {
[selectionViewController startIntroAnimation];
}];
}
First I checked what happens when I use the default navigation controller segue. And to my surprise the animation did start. Then I inserted the call to the [selectionViewController startIntroAnimation] to the completion block and this works as well.
Im trying to present a view translucently and that the previous view sticks around and be that its visible in the background.
I've got
[self presentModalViewController:modalView animation:YES];
and I have the transparency set in the modalView's viewDidLoad, but after modalView gets brought up the previous view disappears. What can I do to keep the other view to stay around in the background?
I have also tried adding it with
[self.view addSubview:modalView.view];
It doesn't cover the whole screen, I would like to be able to solve this problem using presentModalViewController method.
It sounds like you just want a view to be displayed on top of your main view. Modal views are a finicky way of presenting subviews, instead you should look at creating a simple view class to add to your view controller. You can then use [UIView animate...]; method to animate it in and out of view.
To get you started:
- (void)displayViewButtonPressed(id)sender
{
if (!self.topView)
{
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(44.0f, 22.0f, 40.0f, 44.0f];
[overlayView setAlpha:0.0f];
[overlayView setBackgroundColor:[UIColor redColor]];
[self setTopView:overlayView];
[overlayView release];
}
[self.view addSubView:self.topView];
[UIView animateWithDuration:0.5
animations:^{
[self.topView setAlpha:1.0f];
}];
}
In the above method we create a custom UIView and animate it into position. We maintain a pointer to it so we can remove it later (like so:)
- (void)dismissViewButtonTapped:(id)sender
{
[UIView animateWithDuration:0.5
animations:^{
[self.topview setAlpha:0.0f];
}
completion:^(BOOL finished) {
[self.topView removeFromSuperView];
}
}
Its a little more work that using modal views, but it gives you much more flexibility in regards to what you use and how you display it.
Hope this helps:)
I'm trying out a multiple view application, but I can't seem to get the first view controller to go away when I bring in the new view controller. I'm laying the second (coming) view controller at index 0, and it's just placing it in the background. I thought the [going.view removeFromSuperview] would remove the original viewcontroller, but that's not what is happening...
UIViewController *coming = nil;
UIViewController *going = nil;
UIViewAnimationTransition transition;
if (answer == YES)
{
coming = boyController;
going = getInfoController;
transition = UIViewAnimationTransitionFlipFromLeft;
}
else
{
coming = girlController;
going = getInfoController;
transition = UIViewAnimationTransitionFlipFromLeft;
}
NSLog(child);
[UIView setAnimationTransition:transition forView: self.view cache:YES];
[coming viewWillAppear:YES];
[going viewWillDisappear:YES];
[going.view removeFromSuperview];
[self.view insertSubview:coming.view atIndex:0];
[going viewDidDisappear:YES];
[coming viewDidAppear:YES];
[UIView commitAnimations];
First a little refactoring:
coming = (answer ? boyController : girlController);
You can delete going and transition, as they're only used once. Then, to actually do the animation, you need to put everything in the context of an animation block.
[UIView beginAnimations:#"flipAnimation" context:NULL];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[getInfoController.view removeFromSuperview];
[self.view addSubview:coming.view];
[UIView commitAnimations];
viewWillAppear: and viewWillDisappear: are delegate methods. These will be called automatically on those views' delegates, if any. They shouldn't ever be called manually.