Animate NSStatusItem View on 10.9 Mavericks - core-animation

I am trying to implement a custom NSView (layer based) with animations in an NSStatusItem's view.
Animating the layer with CABasicAnimation works well with one screen (menu bar), however stops working when I have two screens attached. It then only animates in one menu bar (the active one). If I click on the other one it then becomes active and starts animation. The other one then stops animating.
The release notes from Apple 10.9 release notes say that one needs to "redraw in NSDefaultRunLoopMode" for the clone to redraw.
How do I perform an NSLayer animation in a different run mode to get the animation running on both/multiple manu bars?
Currently my animation looks like this:
CABasicAnimation *an = [CABasicAnimation animationWithKeyPath:#"opacity"];
an.fromValue = #(1.0);
an.toValue = #(0.0);
an.duration = 0.35;
an.repeatCount = 100000;
an.autoreverses = YES;
[self.outerCircle addAnimation:an forKey:#"opacityAnimation"];
What will I need to change in order to get the animation running on the cloned menu bar as well.
It has to be possible as the seconds from the clock app are up to date on all menu bars as well.

Related

Animate view and set button backgroundimage conflict

I am making a type of drawer animation for iOS where a button tap in one of my views will expand that view over the other views from the bottom up. All is well, except when I want to change the button image after animation. The animation completes but then returns the view to its original position when setting the button image.
Things I have tried:
Using CGAffineTransformMakeTranslation instead of setCenter; this works perfectly, except I want to also add a panGestureRecognizer to interact with the drawer, present, and dismiss it. The transform doesn't seem to play well with this interaction
Adding the buttons programmatically thinking maybe AutoLayout is fussing with this
UIView beginAnimations as well as UIView animateWithDuration and completion block
Setting breakpoints and verifying that the movement of the view is reflected in the frame of the button before the image is changed; button frame is not still in original position, but has supposedly relocated with the view
It shouldn't matter, but my project is using TabBarController. I made a simpler version of what I'm trying to do with just the one view controller and had the same issue. The green view extends beyond the frame of the view controller's view so that when it moves up it reveals what is off-screen.
example: http://i.imgur.com/tRou0Js.png?1

how to do a "app launch like" fade - zoom ios 7 transition?

I need to achieve the IOS7 app launch transition, in which the the detail view appears with fade effect according to the rectangle frame of the button that fired this view, as described in the image below:
So I have a main ViewController with six buttons, I want to make transition to the details viewControllers with fade and zoom effect, and starting the animation depending of the button frame.
I found RZTransitions, amazing collection of custom transitions, it does exactly what I want but for uicollectionView, I tried but can't get working to do the same for a viewController.
Thanks.

UINavigationViewController changes the behaviour of scroll view in iOS7

I have a 'UIScrollView' that is supposed to display a list of images one next to the other. This is the code I'm using to add each image:
#define SCROLL_PADDING 10
#define SCROLL_DIMENSIONS 50
view.frame = CGRectMake(xValue, SCROLL_PADDING, SCROLL_DIMENSIONS, SCROLL_DIMENSIONS);
[scroller addSubview:view];
However, as shown in the image below, the images are loaded with a vertical offset. After some research I realised that this offset is the same as the height of the navigation bar's height.
Note 1: By default the images cannot be seen. I had to scroll up to make them visible.
Note 2: I shouldn't be able to scroll because the images should fit in the scroll view.
I decided to present the view controller modally instead of pushing it to the hierarchy of the navigation view controller and everything work as expected.
This problem only happens in iOS7. Any ideas why?
I came across this article, which clearly explains various changes in status bars and navigation bars on iOS7
As you can see in both of the images above, the position of the scroll view doesn't change. In iOS6 if the subview's frame doesn't change, it would be moved down to prevent it from underlapping the navigation bar. Since iOS7 it is expected that all subviews will underlap not only the navigation bar but also the status bar, which makes the location (0, 0) the top left of the SCREEN.
For some reason that I don't understand yet (it would be nice if somebody could explain), only the scroll view's subviews where moved down in the same way it was being done in iOS6. Hence making the subviews appear out of the scroll view's bounds.
To prevent the subviews from underlapping the navigation bar it is necessary to set edgesForExtendedLayour to UIRectEdgeNone as early as possible in the life cycle of the view controller
viewController.edgesForExtendedLayout = UIRectEdgeNone;

Making a nav controller work the same in iOS 6 and iOS 7

How can a navigation bar be supported in both iOS 6 and iOS 7 with a UIContainerView via a storyboard?
I am updating an iOS 6 app to iOS 7, but want to continue to support iOS 6. I have a main top level view that is embedded within a UINavigationController. The view within the navigation controller has a container view in it. I am using a storyboard to lay out the view.
On iOS 7 the navigation controller uses the entire screen, and I've set it up to put the container view content below the navigation bar. In iOS 6 the content of the view does not go under the navigation bar, so I have a blank gap below the nav bar.
Normally I would just reset the origin of the offending view on iOS6 (in ViewDidLoad or somesuch) and go on my way. However since my content is in a UIContainerView, I can't seem to change the frame after it loads. (I have tried this in prepareForSegue: when loading the UIContainerView. I'm open to having done this wrong? heh)
The closest I have found is using the following code under iOS 7 to make the nav bar opaque and keep the content out from under it, then using the entire space for my UIContainerView.
// tell the view to not extend below this nav bar
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
This solution works but has the side effect of showing the status bar as black (since it's more or less "blank" under the status bar). Alternatively, if I put the top edge of the container view below the status bar, on iOS 6 I have a big gap below the navigation bar.
I can eliminate the use of a navigation controller, but that seems a bit heavy handed in this situation and I'd like to use that as a last resort.
I've found the solution to this.
You need to set the barTintColor in iOS 7, which also seems to color the main status bar, as well as setting the nav bar to not be transparent like this:
mainController.navigationBar.barTintColor = [SRPRTabletHelpers customUserColor];
mainController.navigationBar.translucent = NO;
The non-transparency was the key, while setting the color sets not only the regular nav bar, but the color beneath the status bar as well.
I also needed to change my containerView top edge to be the full height of my view contained within the navigation controller, now that it is not transparent, and it works the same on both iOS6 and iOS 7.
While you mention to have already solved this, your method seems to require a lot of manual code and if checks. The iOS 7 UI Transition guide, in the Supporting iOS 6 chapter mentions another way: first design your interface for iOS7 as you have done, with your view extending below the navigation bar.
Then, in the interface builder open the size inspector for UI elements and modify the iOS 6/7 deltas. These values are applied when the storyboard is not run on iOS 7. For example, in your case you can select all your visual elements, then set the Y delta to -44, which is the standard navigation height. That will make the UI go up on iOS6, compensating the fact that the view doesn't go under the navigation bar.

XCode Redraw portrait layout with double high status bar

I'm having this issue with several screens in my app, but I'll explain what happens to my home screen. Hopefully the solution isn't as complicated as I'm thinking it will be. So my home screen has a logo at the top, a label(title) under that, 3 horizontal buttons under that, and finally, settings and info buttons in the bottom left and right hand corner respectively when if portrait orientation. In order to allow for landscape orientation, resizing masks were not able to achieve the look I wanted so I implemented the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
method with an if and else statement, the "if" uses CGRectMakes to draw all of the elements where they should go in landscape layout, and the "else" redraws them back to their original places when changed back to portrait landscape. This all works very nicely. I remembered that we had to be able to handle the double high status bar, so I simulated it to see what it would do to my app. When I am on the home screen and toggle it on and off, the autoresizing of the items(which are set to adjust according to the top of the view) work nicely, by slightly squishing everything down a bit, and not hiding anything. I can toggle it off and on with no problems.
Now here's the problem:
When I have the double high status bar toggled on while on a different screen, then go back to my home screen, the resizing doesn't happen, and it redraws my screen full size according to the coordinates and sizes I have in the method I mentioned earlier, so the settings and info button are drawn halfway off the bottom of the screen. Same happens when switching from landscape back to portrait on the homescreen with the double high status bar already on.
Similarly, I have a map between a nav and tab bar on another page. When already on the page, and toggling it on and off, everything resizes nicely(the frame of the map changes height and the nav bar moves down). But again, I have a problem when switching to that screen from a different screen or from the landscape orientation, because instead of autoresizing appropriately, the map view and nav bar get pushed down behind the tab bar partially, obscuring the google trademark which is grounds for app rejection.
Sorry for the longwindedness, but I wanted to clearly describe what circumstances cause this problem. Any ideas would be greatly appreciated as I don't really have any idea how to approach this.
I've been trying to track down this problem myself. I think this happens because the autoresizing mask is only used when views are resized, and not when a new view is added to the scene.
For me, I wanted a settings view loaded from a nib and added on top of everything else. If the double-height bar was in effect when the view was added it would run off the bottom of the screen. To fix it you have to set the size and position of the view yourself when you load it. This is the code behind my working 'goto settings' button:
- (IBAction) settingsPressed:(id)_sender
{
NSArray* a = [[NSBundle mainBundle] loadNibNamed:#"SettingsView" owner:self options:nil];
SettingsView* settings = [a objectAtIndex:0];
settings.frame = self.view.bounds;
[[self view] addSubview:settings];
}
The important line being:
settings.frame = self.view.bounds;
Which, it would appear, classifies as a 'resize' and so the resizing-mask rules apply. I later added animations for the transition and it continues to work just fine.
Note: This method was in a View Controller.