Strange graphics glitch when using flip animation - objective-c

I'm getting a strange error when committing a flip animation. These three bars show up, almost like strips that aren't being drawn too.
I got a screenshot to show what I'm talking about. These lines are always in the same place, and show up on both sides.
graphics glitch screenshot http://img263.imageshack.us/img263/6079/animationglitch.jpg
Here is the code that I'm using, I've used it before without problems, so I'm not sure whats goin on.
-(void)switchView
{
BOOL isChangingToMapView = _mapViewController.view.superview == nil;
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:(isChangingToMapView ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight) forView:self.view cache:YES];
if (isChangingToMapView)
{
[_mapViewController viewWillAppear:YES];
[_listViewController viewWillDisappear:YES];
[_listViewController.view removeFromSuperview];
[self.view insertSubview:_mapViewController.view atIndex:0];
[_listViewController viewDidDisappear:YES];
[_mapViewController viewDidAppear:YES];
}
else
{
[_listViewController viewWillAppear:YES];
[_mapViewController viewWillDisappear:YES];
[_mapViewController.view removeFromSuperview];
[self.view insertSubview:_listViewController.view atIndex:0];
[_mapViewController viewDidDisappear:YES];
[_listViewController viewDidAppear:YES];
}
[UIView commitAnimations];
}
Any ideas as to what could be causing this?

Well I banged my head off of this problem for awhile and then moved on. Then I had the bright idea to try it on the actual phone. Sure enough it runs properly on the phone.
Just a little reminder, if you are having weird problems developing on the simulator, at least try your app on the phone before you waste to much time chasing a bug made by the simulator.

Related

Problems with iAds and iOS 8

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!

Animating with Auto Layout and iOS7 jumps to end of animation (fine in iOS6)

I am using Autolayout and animating by changing the constraints, however, in iOS7 the view simply jumps to the end position - in iOS6 I get a nice animation.
Is should be noted these views are UICollectionViews and I have checked the Storyboard and there are no Layout errors.
All I can think is there is something and am or am not setting on the Storyboard or something that I am doing wrong with the Constant settings in the Storyboard.
primaryMenuYContraints.constant = BUTTOMX;;
leftMenuYContraints.constant = 136.0f;
leftMenuBottomConstraint.constant = 5.0f;
[UIView animateWithDuration:0.7f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^
{
// Move in menus
[self.primaryOptionCollection layoutIfNeeded];
[self.menuOptionCollection layoutIfNeeded];
}
completion:^(BOOL finished)
{
}];
I changed to and now works in both iOS7 and 6, still not sure why it does/did it though! I still think I am setting something up wrong in the Storyboard. I am add another view (nothing to do with this lot) programmatically so I believe that is based around frames until I convert it (which I am not doing).
primaryMenuYContraints.constant = BUTTOMX;;
leftMenuYContraints.constant = 136.0f;
leftMenuBottomConstraint.constant = 5.0f;
[UIView animateWithDuration:0.7f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^
{
// Move in menus
[self.view layoutIfNeeded];
}
completion:^(BOOL finished)
{
}];

Fading UIView allows subviews to be seen

I have a UIScrollView which contains various subviews (UIImageViews, UILabels and standard UIViews). Some of the UIImageViews are partially covered by other UIViews.
However, when I fade out the UIScrollView, the partially covered parts of the UIImageViews are being exposed for the brief moment of the animation.
I want to be able to fade the scrollview and all it's contents at the same time in the same animation - i.e. not revealing any of the partially covered images.
If it's not possible, I can always add a UIView on top of all the other controls and fade it from alpha 0 upto 1 to hide everything, but I'm sure there's a way to perform a complete fade on a view and all it's subviews.
I tried this:
[UIView beginAnimations:nil context:NULL];
[scrollViewResults setAlpha:0.0f];
[UIView commitAnimations];
And I've tried this:
- (IBAction)questionGroupChanged:(UIButton*)sender {
[UIView beginAnimations:nil context:NULL];
[self fadeViewHierarchy:scrollViewResults toAlpha:0.0f];
[UIView commitAnimations];
}
- (void)fadeViewHierarchy:(UIView*)parentView toAlpha:(float)alpha {
[parentView setAlpha:alpha];
for (UIView *subView in parentView.subviews) {
[self fadeViewHierarchy:subView toAlpha:alpha];
}
}
But I've still not cracked it. Any ideas?
This happens because of the way the compositor works. You need to enable rasterization on the view's layer when fading it in/out:
view.layer.shouldRasterize = YES;
You should probably only enable this for the duration of the animation because it will take up some extra memory and graphics processing time.
Mike's answer is the correct one and he deserves all credit for this. Just to illustrate, it might look like:
- (void)fadeView:(UIView*)view toAlpha:(CGFloat)alpha
{
view.layer.shouldRasterize = YES;
[UIView animateWithDuration:0.75
animations:^{
view.alpha = alpha;
}
completion:^(BOOL finished){
view.layer.shouldRasterize = NO;
}];
}
Thus, using your scrollViewResults, it would be invoked as:
[self fadeView:scrollViewResults toAlpha:0.0f];
Did you try with UIView class methods +animateWithDuration:* (available on iOS 4 and +)
Like :
- (void)fadeAllViews
{
[UIView animateWithDuration:2
animations:^{
for (UIView *view in allViewsToFade)
view.alpha = 0.0;
}
completion:^(BOOL finished){}
];
}

List examples of how to "briefly draw attention" to an object on screen in iOS?

In iOS, how can one briefly draw attention to an object on screen? Suppose, create a brief glow or cause a shadow to appear and then disappear?
For the purposes of this question, let's define "object on screen" as an instance of UIImageView.
Also, if possible provide an example of how to draw attention to a button.
Most people list code, but I'm sticking to describing some examples;
I've seen objects briefly grow and shrink back to their normal size to draw attention
Bejeweled (a Popcap game) lets diamonds briefly 'shine' (as if sunlight passed over it) to give you a subtle hint
I've seen certain applications use a hand or a fictive character point to a certain object briefly
And of course, you could always introduce a talking paperclip to tell you what's what.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1f];
yourView.transform = CGAffineTransformMakeScale(1.1, 1.1);
[UIView commitAnimations];
Or, of course the same thing with a block animations. And after the attention got away from your view you can use :
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.1f];
yourView.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
Here is a simple hop animation...
- (void)drawAttn
{
float jumpHeight = 20.0;
CGPoint originalPoint = objectForAttn.center;
CGPoint jumpPoint = CGPointMake(objectForAttn.center.x, objectForAttn.center.y - jumpHeight);
[UIView animateWithDuration:0.20 delay:0.0 options:UIViewAnimationOptionAutoreverse animations:^{
[objectForAttn setCenter:jumpPoint];
} completion:^(BOOL finished) {
/* do other stuff after hop */
}];
}
My app QCount (free in the store, tap a "wrong" number 3 times) uses a fade animation as follows:
(note I wrote this when I was REALLY new to iOS, so there is probably a more compact way to write it)
aLabel = // a UILabel I get from somewhere
aColor = aLabel.backgroundColor;
[UIView animateWithDuration:0.2
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
aLabel.alpha = 0.0;
}
completion:^(BOOL finished){
// Wait .2 seconds and then fade in the view
[UIView animateWithDuration:.2
delay: 0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
aLabel.alpha = 1.0;
}
completion:nil];
}];
There are lots of options: hopping, underlining, vibrating, blinking, rotating, scaling, endarkening around, and their combinations.
But IMO, shine effect on "slide to unlock" text is excellent.
You can check it out here:
iPhone "slide to unlock" animation
I wanted to draw attention to a label whose value had changed. This simple animation produces a nice 'I've changed' animation...
//copy the label
UILabel *newPageLabel = [[UILabel alloc] initWithFrame:_countLabel.frame];
[newPageLabel setFrame:CGRectOffset(newPageLabel.frame, 0, 0)];
newPageLabel.text = _countLabel.text;
newPageLabel.textAlignment = _countLabel.textAlignment;
newPageLabel.backgroundColor = _countLabel.backgroundColor;
newPageLabel.textColor = _countLabel.textColor;
newPageLabel.font = _countLabel.font;
//scale and fade out the copied label
[self.navigationController.toolbar addSubview:newPageLabel];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionLayoutSubviews
animations:^{
newPageLabel.transform = CGAffineTransformMakeScale(2,2);
newPageLabel.alpha = 0;
}
completion:^(BOOL finished){
[newPageLabel removeFromSuperview];
}
];

Animations taking extra memory

I need to use animation in my iPad application.When I use the animations the memory is increasing and getting exception..When I launch my application the size of the memory is 10 mb, once the animations are started it is increasing the memory size upto double of the launch space (it is 30 mb). I test for the allocations and leaks everything is perfect but still I got this problem. I don't know why it is happening. My animation code is as follows.Please help me.
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
if ([currentView superview])
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainView cache:YES];
[currentView removeFromSuperview];
[mainView addSubview:nextView];
}
[UIView commitAnimations];
Thanks in advance,
Sekhar Bethalam.
How sure are you that the animation is causing the leak?
What happens when you add/remove subviews without the animation? Is the leak still there?
Where is nextView initialized/released?
What exactly is if ([currentView superview]) meant to check for because I think it'll always return True?
I'm not sure if it's the method itself that is increasing the memory usage but likely your view controller that's being loaded in?
Also try adding these lines in your animation block as I think it's encouraged (please correct me if I am wrong)
[currentView viewWillAppear:YES];
[currentView viewDidAppear:YES];
[mainView viewWillDisappear:YES];
[mainView viewDidDisappear:YES];
Also I believe setAnimationTransition is now discouraged in IOS4 so maybe try using
+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion