Apple

dynamically change circle size held in NSBezierPath

Posted in Apple, Uncategorized on July 26th, 2010 by Saba – Be the first to comment

When a user decides to display a scatter plot, I iterate through all my points and add the x,y points to an NSBezierPath as such with a fixed width and height.

- (void) addCoord:(double) xval yCoord:(double) yval { NSRect rect = NSMakeRect(xval, yval, 1, 1);

[circlePath appendBezierPathWithOvalInRect:rect]; }

Then drawRect: gets called which draws my scatter plot coordinates. The problem is that, my circles are already drawn to a certain size and I need to scale my circles proportionately with my screen size and I don’t know what size this will be till drawRect: gets called (e.g. the user may be resizing the window).

NSBezierPath *copyPath = [circlePath copy];

// Move to center of screen. NSAffineTransform *xform = [NSAffineTransform transform]; [xform translateXBy:(bounds.size.width * 0.50) yBy:(bounds.size.height * 0.50)];

// Scale proportionately to screen size. [xform scaleBy:(xFactor / 2)];

[copyPath transformUsingAffineTransform:xform];

[[NSColor yellowColor] setStroke];

[copyPath stroke];

Anyone have suggestions on how to dynamically change my circle size for the points which are all held within an NSBezierPath?

Problem with OSALoadFile()

Posted in Apple on July 25th, 2010 by Saba – Be the first to comment

On 7/25/10 12:27 PM, Joshua Juran wrote:

Looks like the problem was that theComponent was a struct, and I needed to point to the appropriate field within the struct. theComponent->theComponent.

NSBrowser and double click

Posted in Apple, Uncategorized on July 25th, 2010 by Saba – Be the first to comment

On 25/07/2010, at 9:00 AM, mark wrote:

In general this is the expected behaviour. Most stuff that handles multiple selection doesn’t wait to see if a click is going to end up as the first of a double-click, and so processes the first click in a straightforward way. Typically, this is to deselect everything except what was clicked (unless modifier keys are down that might extend or flip the selection). On the second click, the double-click is detected and the double action triggered.

It is possible to be smarter when processing clicks and wait to see if a second click arrives within the double-click time before processing the first click, but you rarely see code that does this, since for one thing it seems unresponsive – every single-click will have no effect until the double-click period elapses.

If you were me, how do you build mind map app on cocoa?

Posted in Apple on July 25th, 2010 by Saba – Be the first to comment

I am a new to Cocoa and planning to build an app like mind map.

This is my guess on how to build mind map like app on Cocoa. Please check and let me know if you know any more efficient approach or some missing pieces I should consider.

Deselect keyboard focus of an NSMatrix cell

Posted in Apple on July 25th, 2010 by Saba – Be the first to comment

On Jul 24, 2010, at 3:03 PM, Jochen Moeller wrote:

I notice that in your last email you didn’t mention calling -endEditingFor:. Did you try this? What were the results?

NSControl with CALayer in NSToolbar

Posted in Apple, Uncategorized on July 25th, 2010 by Saba – Be the first to comment

Hello,

I creted an IB Palette for control with CALayer I animate. This layer is a sublayer of the [control layer]. Control works normally in the IB, the IB Simulator and also in my test application. When I use this control as a NSToolbarItem item of NSToolbar, drawLayer: in my delegate is never called when the NSToolBar is in customize state in the IB Simulator or in my test application. If I open customize window of NSToolbar in the IB (while in desgin mode), drawLayer: is called and draws what I need. If I drag the item from the NSToolBar’s customize window to app window (in IB Simulator or test app), drawLayer: is called and everything works.

I also noticed that when I use any of Apple NSControls in NSToolbar and set them to WantsLayer:YES in IB Inspector, add some shadow, just to see if CALayer effect works, control’s layer also doesn’t work in NSToolBar in customize state – so no shadow while customize window of NSToolbar is open. I think it is somehow related to NSMatrix (I suppose NSToolbarItems are arranged in NSMatrix …)

Any idea how to fix it ?

Thank you.

Peter

Nested UIScrollView: horizontal scrolling

Posted in Apple, Uncategorized on July 24th, 2010 by Saba – 1 Comment

Hello,

I’m trying to scroll horizontally through a set of pages, where pages are grouped by two (and can be zoomed both together). So far, my view hierarchy is:

• One outter UIScrollView that scrolls horizontally. • Several inner UIScrollView that contains two pages each, scrolling horizontally too.

The problem I have is that swiping quickly through pages makes the outter UIScrollView skip the inner pages : only the first page of the inner SV are visible, and then the outter UIScrollView skip directly to the next page group.

It seems that as long as the outter SV is moving (or decelerating, anyway), the inners SV won’t have a chance to get the swipe events.

I tried several things so far :

• Use touchesShouldBegin:withEvent:inContentView:: If delaysContentTouch is disabled, this is called during multiple swipes — however touchesShouldCancelInContentView: is only called for the first swipe, and it’s probably what would be usefull. So no luck there (I think). • Disable scrolling on the outter SV (scrollEnabled = NO) when entering a page group, and re-enable it when the inner SV started to scroll (as then the inner SV will catch all the swiping events): my best try so far. However it’s hard to detect which page group we’re going to land on after several swipes. Plus it seems that an existing touch is not re-aquired right after scrollEnabled is re-activated, so I miss a few swipes, and the animation is not smooth as it should be (the scroll stops flatly on groups ends, then resumes on next swipe).

(Btw, the problem occurs whether paging is enabled or not: it really lies in the horizontal swipe handling, not in the paging behavior.)

In the end, my question is: how can I prevent the outter UIScrollView from getting all swipe events when it’s decelerating, and tell it to pass them to the inners UIScrollViews instead?

Additional questions: How does the magic of nested UIScrollView actually works ? And would overriding ‘hitTest:’ on one of the ScrollViews be a good idea ?

I arranged a small sample Xcode project that demonstrates the issue and the possible fixes — it is available here : http://winosx.com/hosted_files/ZoomScrollTest.zip

Thanks!_______________________________________________

is there another way of drawing a Pixel in NSView apart from NSBezierPath?

Posted in Apple on July 24th, 2010 by jabeer – Be the first to comment

I am trying to plot an 640×640 image by computing the color for each pixel and using NSBezierPath:fillRect function. But it takes about 1.5s to draw the entire image. I found out that the fillRect function is what is taking the time and not the computation. I can use NSOpenGLView and make it draw within a fraction of a second, but the image quality is bad. Is there any way for just plotting a point rather that plotting a 1*1 rect and then filling it?

NSPropertyListSerialization and string encoding

Posted in Apple on July 23rd, 2010 by Saba – Be the first to comment

Hey,

No one is requiring me to send a string–I do indeed send it as data, but I must convert values from string to data. Like, I have a title field, in which I must convert the title to NSData. But since there are a bunch of arguments like this, I just make a string like @”arg1=something&arg2=something…”, and then do [dataUsingEncoding:allowLossyConversion:.

Should I be doing this a better way? (I’m the one who created the web service, so if there’s an issue with doing it this way, I can easily change it).

Joe On Jul 23, 2010, at 11:31 AM, Kyle Sluder wrote:

print object by %@

Posted in Apple, Uncategorized on July 22nd, 2010 by Saba – Be the first to comment

Thank you for yours, but I am looking for more convenient way, I mean a function for console output, not for debugging like NSLog(),

so I wish:

NSLog(@”object is %@”, obj); // $ object is [object description]

I would not wish to convert NSString to utf8 for printf(), I wish to use NSString 2010/7/22 Jean-Daniel Dupas