If you programmatically create subview or control, you better do it in viewDidAppear. Only at that time your view's size is finalized. Before that, if you use your view's size to determine the location of your subview or control, it may be wrong since your view may be resized.
Another solution is to use setAutoresizingMask, e.g., if your button is at the bottom of the screen, you need setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin. If the view height changes, your button goes with it.
Sunday, 2 June 2013
iOS: share methods between classes
Two classes can shared methods through category. For example, you have two subclasses of UIViewController. You want to add some common methods to both, then you can create a UIViewController category which contains these common methods.
Saturday, 25 May 2013
iOS: macro for minimum supported target iOS version (deployment target)
Each Xcode project has a deployment target, that is the minimum iOS version your application should support.
Sometimes you need to use different code for different deployment target, here is an example:
Sometimes you need to use different code for different deployment target, here is an example:
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 60000
[self presentModalViewController:webViewController animated:YES];
#else
[self presentViewController:webViewController animated:YES completed:nil];
#endif
Thursday, 23 May 2013
UIKit: Simple way to disable gesture recognizer in subview
Sometimes you have gesture recognizer with a view but want to disable it for a subview (e.g. you use the subview as a toolbar). By default you can click "through" the subview as if it does not exist, which can cause confusion. A simple way to disable gesture recognizer in a subview is in UI builder to drag new a gesture recognizer onto the subview, which associates a gesture recognizer with the subview which does nothing when the gesture is recognized.
If you want the child of the subview (e.g. some buttons in this subview) to receive taps, uncheck its "Canceled in view" property.
If you want the child of the subview (e.g. some buttons in this subview) to receive taps, uncheck its "Canceled in view" property.
OpenGL ES 1.1: How to convert world coordinates to UIView coordinates
Assuming world coordinates is in worldp of type vec4, UIView window size is in bounds.size, the following code converts world coordinates to UIView coordinates:
mat4 modelview;
mat4 projection;
glGetFloatv(GL_MODELVIEW_MATRIX, (float*)modelview);
glGetFloatv(GL_PROJECTION_MATRIX, (float*)projection);
vec4 eyep = worldp * modelview * projection;
eyep = eyep/eyep.w;
screenp.x = (1+eyep.x)/2*bounds.size.width;
screenp.y = (1-eyep.y)/2*bounds.size.height;
Friday, 17 May 2013
Eclipse: recover overwritten files
If you overwrote a new file with an old file by mistake, Eclipse may be your only life saver. It has a feature called local history, which automatically records all the changes you made to a file. If you want to revert a file to an old edition, just right click the file in the left panel, and choose team/local history, then select a date to recover.
That's one reason I like Eclipse. Actually today it just saved me several days' of work when I accidentally reverted my file to an old revision in a version control system by mistake.
That's one reason I like Eclipse. Actually today it just saved me several days' of work when I accidentally reverted my file to an old revision in a version control system by mistake.
Sunday, 12 May 2013
OpenGL ES 1.1: texture mapped object has wrong color
If you use texture to get exact color for an object, make sure at the texture coordinate the texture does not change color suddenly. If so, you will get interpolated color instead of exact color. If the texture coordinates are at the corner or boundary of the texture, make sure the color at the other 3 corners or the reflected boundary are the same, otherwise you may get unwanted interpolated color.
Subscribe to:
Posts (Atom)