Re: Display an Alert Sheet at a Specified Screen Position
Re: Display an Alert Sheet at a Specified Screen Position
- Subject: Re: Display an Alert Sheet at a Specified Screen Position
- From: Graham Cox <email@hidden>
- Date: Fri, 27 Mar 2015 10:00:02 +1100
> On 26 Mar 2015, at 10:57 pm, Dave <email@hidden> wrote:
>
> i tried this just to get something working for now, but it doesn’t seem to affect where the Alert is displayed.
>
> myAlert = [NSAlert alertWithMessageText:@"Do you really want to do that?" defaultButton:@“No" alternateButton:@“Yes" otherButton:nil informativeTextWithFormat:@"It might cause mayhem!”];
>
> myAlertWindow = myAlert.window;
> myAlertWindowFrameRect = myAlertWindow.frame;
> myAlertWindowFrameRect.origin = myNewOrigin;
> [myAlertWindow setFrame:myAlertWindowFrameRect display:YES];
>
> myAlertResponse = [myAlert runModal];
> if (myAlertResponse == kDialogResponseYes)
> {
> }
> else
> {
> }
>
At the point you're setting the frame, the window isn't visible. -runModal shows the window if necessary and positions it on screen, overriding the frame you set. If you force it to be visible before -runModal is called, the frame position you set is not changed. This works:
NSAlert* alert = [NSAlert alertWithMessageText:@"hello" defaultButton:@"ok" alternateButton:@"cancel" otherButton:nil informativeTextWithFormat:@"bing bang wallah wallah bang"];
[alert.window setFrameOrigin:NSMakePoint( 10, 100)];
[alert.window makeKeyAndOrderFront:nil];
NSInteger result = [alert runModal];
NSLog(@"response = %ld", result);
> I’ll investigate doing it using a sheet next week, but it would be nice to have the Alert working in the meantime.
Your requirement isn't clear - do you want a sheet to appear as if unattached to a host window, just floating in space? Even if you can achieve it, users will simply assume your app is buggy. Ideas like this are never seen in the wild for good reason.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden