I have a button that triggers the main window to animate it's height thus displaying some options in a pull-down-menu. The button (and it's sibling) are placed in the two bottom corners of the window, so i want them to animate down with the window - being "locked" in a fixed distance from the bottom window edge.
Problem: The buttons animate properly maybe 1 out of 10 times - the rest of the time they get offset seemingly randomly on the y-axis. On top of that the two buttons get different offsets - they don't behave identical, although the animation code is the same.
Deployed and run on OSX 10.9 Mavericks the animation works properly - no misbehaving there.
Any ideas on how to get the following, simple code to work on OSX < 10.9?
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.2f];
[[[self window] animator] setFrame:NSMakeRect([self window].frame.origin.x, [self window].frame.origin.y-EXTRA_HEIGHT, ORIGINAL_WIDTH, ORIGINAL_HEIGHT+EXTRA_HEIGHT) display:YES];
[[_buttonOne animator] setFrameOrigin:NSMakePoint([_buttonOne frame].origin.x, CONSTANT_NUMBER)];
[[_buttonTwo animator] setFrameOrigin:NSMakePoint([_buttonTwo frame].origin.x, CONSTANT_NUMBER)];
[NSAnimationContext endGrouping];
Related
NSWindow not placed on right frame in second screen.
With new OSX version I have the problem that I can set Frame but NSWindow will not set on correct screen. Only if I use setFrame animated works.
But it looks strange and cost performance. Somebody know what can help...
I try many things... but only animation bring window to the right NSScreen.
[fullScreenWindowPlaylist setFrame: screen.frame display:YES]; // not work
[fullScreenWindowPlaylist setFrame: screen.frame display:YES animate:YES]; // works
Greetings
I have an NSScrollView with a custom NSImageView as its document view set up in the xib file. My problem comes when I want to magnify the NSScrollView. I would like it to behave like the Preview app on Mac, and I can get it to magnify just fine, but I want it to magnify with the cursor as the centered point.
I have this code in my custom NSScrollView class:
//Informs the receiver that the user has begun a pinch gesture.
- (void)magnifyWithEvent:(NSEvent *)event {
NSPoint conViewPoint =[[self contentView] convertPoint:[event locationInWindow] fromView:nil];
[self setMagnification:[event magnification]+[self magnification] centeredAtPoint:conViewPoint];
}
This works, however it also causes the scroll view to scroll down as it magnifies (though it doesn't move sideways at all). It's more noticeable when zooming in and out multiple times without lifting from the trackpad.
A similar problem seems to be in this question, however I'm using a pinch gesture and not buttons. I've been trying to offset the y axis scrolling as suggested for that question with
[[self documentView] scrollPoint:scrollPoint]
but I haven't been able to figure out a working formula for scrollPoint that accounts for the changing content view bounds to keep the point under the cursor in the same place. So, I'm wondering if there is a more proper approach to this or if the scrolling really is needed and I just need to figure out the math.
Thanks for any help with this
EDIT:
So I finally figured out the scrolling math. It took a while and way more complicated attempts, but is pretty simple in the end:
- (void)magnifyWithEvent:(NSEvent *)event {
NSPoint docViewPoint =[[self documentView] convertPoint:[event locationInWindow] fromView:nil];
NSPoint docRectOri=[self documentVisibleRect].origin;
float widthGapSize=-docRectOri.x;
float heightGapSize=-docRectOri.y;
if([event phase]==NSEventPhaseBegan){
startDocPoint=docViewPoint;
startPoint.x=(docViewPoint.x+widthGapSize)*[self magnification];
startPoint.y=(docViewPoint.y+heightGapSize)*[self magnification];
}
scrollPoint.x=startDocPoint.x-(startPoint.x/[self magnification]);
scrollPoint.y=startDocPoint.y-(startPoint.y/[self magnification]);
[self setMagnification:[event magnification]+[self magnification] centeredAtPoint:docViewPoint];
[[self documentView] scrollPoint:scrollPoint];
}
I still don't understand why setMagnification:centeredAtPoint: doesn't just work and am still wondering if anyone has some input on this as my workaround is very jittery on magnification because of the scrolling.
I'm experience the strangest thing. I'm working on a project that I started noticing this issue, so I created a sandboxed test to simplify the problem and see if I can figure it out.
I have document based application with a single window controller. inside that are these objects:
Subclassed NSScrollView with isFlipped=YES
Subclassed NSView with isFlipped=YES, this is the documentView in the above scrollview.
An NSImage in the document view
Then I try and fade the image to alpha 0 like this:
- (void)windowDidLoad {
[super windowDidLoad];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(test) userInfo:nil repeats:FALSE];
}
- (void) test {
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:4];
self.errorOutline.animator.alphaValue = 0;
[NSAnimationContext endGrouping];
}
This is how it looks in Xcode:
This is what happens when it starts animating:
I've noticed that if I resize the window continually while it's animating, I get a ghosting image like effect where I an see the rest of the image.
Another strange issue is that if I set isFlipped=NO, then the issue doesn't happen. Which is not an option - the whole reason I'm flipping the view is so it's easier to manage adding cells to it without calculating positions and heights backwards.
Update: I've filed a radar bug as this is a really strange issue. http://openradar.appspot.com/20680289
Im using Xcode to make an application that has a NSImageView that I have made into an NSScrollView (I think) by means of selecting it in my .xib, going to the editor menu in Xcode then embedded in > scrollView.
I have an image in my NSScrollView that is larger than the window it is opened in, I can scroll using the scroll bars fine and have even turned on the autoscroll: function in my mouseDragged: method.
I would like to be able to simply pan around the image without touching the edges of the screen using mouseDragged:. So far my code for mouseDragged: in my panning.m(subclass of NSImageView) is such:
-(void)mouseDragged:(NSEvent *)theEvent{
NSPoint p = [theEvent locationInWindow];
[self scrollRectToVisible:NSMakeRect(p.x - self.visibleRect.origin.x, p.y - self.visibleRect.origin.y, self.visibleRect.size.width, self.visibleRect.size.height)];
[self autoscroll:theEvent];
}
This works to some degree, however there is a lot of jittering. Maybe because I am not restricting the bounds?
I was wondering if I am on the right track or is there a better/more efficient way.
Any help is appreciated.
Cheers.
I'm searching for the "best" way of creating a fullscreen overlay under Mac OS X. I want to create a transparent or semi-transparent overlay, which cares about mouse events and shows other input/output elements.
This overlay should be above every other GUI items (like the CMD-Tab overlay).
Do you know how to do it effectively? At the moment I'm playing around with this kind of code:
int windowLevel = CGShieldingWindowLevel();
NSRect windowRect = [[NSScreen mainScreen] frame];
NSWindow *overlayWindow = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO
screen:[NSScreen mainScreen]];
[overlayWindow setReleasedWhenClosed:YES];
[overlayWindow setLevel:windowLevel];
[overlayWindow setBackgroundColor:[NSColor colorWithCalibratedRed:0.0
green:0.0
blue:0.0
alpha:0.5]];
[overlayWindow setAlphaValue:1.0];
[overlayWindow setOpaque:NO];
[overlayWindow setIgnoresMouseEvents:NO];
[overlayWindow makeKeyAndOrderFront:nil];
…and it works fine but I've got no options to initiate any kind of animations like slowly increasing the transparency (slowly dimming the screen) etc.
Although I'm not understanding how to put this window in the background, without releasing it and let it pop up time to time.
So is there a better or "standard" way to do it?
You can use NSViewAnimation. Yes, it works on windows, too.
Your animation's target should be the window, and its effect should be fade-in or fade-out, depending on whether you're showing or hiding it. Leave out the frame keys, since you probably don't want to move or resize the window.
Of course, you should leave out the makeKeyAndOrderFront: message, since you'll be ordering it front with the fade-in effect.