I use pan, a pinch, and UIGestureRecognizers rotation to allow the user to set certain user interface elements exactly where they need them. Using the code here http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more (or similar code here http://mobile.tutsplus.com/tutorials/iphone / uigesturerecognizer / ) both give me what I need so that the user can place these user interface elements as they want.
When the user exits the "UI layout" mode, I save the UIView transformation and center like this:
NSString *transformString = NSStringFromCGAffineTransform(self.transform);
[[NSUserDefaults standardUserDefaults] setObject:transformString forKey:@"UItransform", suffix]];
NSString *centerString = NSStringFromCGPoint(self.center);
[[NSUserDefaults standardUserDefaults] setObject:centerString forKey:@"UIcenter"];
When I restart the application, I read the UIView transform and center like this:
NSString *centerString = [[NSUserDefaults standardUserDefaults] objectForKey:@"UIcenter"];
if( centerString != nil )
self.center = CGPointFromString(centerString);
NSString *transformString = [[NSUserDefaults standardUserDefaults] objectForKey:@"UItransform"];
if( transformString != nil )
self.transform = CGAffineTransformFromString(transformString);
And UIVEW ends correctly and scales correctly, but in the wrong place. In addition, after re-entering the "UI layout" mode, I can’t always capture the view with various gestures (as if the displayed view is not a view understood by the gesture recognizer?)
I also have a reset button that sets the UIView transformto the identifier and it centeranytime when it is loaded from the NIB. But after loading the modified UIView center and conversion, even reset does not work. The UIView position is incorrect.
, , center, ( , ). ( , ), UIPanGestureRecognizer, . , , , , . . .
. UIView , , UIView , ?
, - stackoverflow. , .
. , ( , , , , frame.origin).
, / prefs .
NSString *originString = NSStringFromCGPoint(self.frame.origin);
[[NSUserDefaults standardUserDefaults] setObject:originString forKey:@"UIorigin"];
( ):
NSString *originString = [[NSUserDefaults standardUserDefaults] objectForKey:@"UIorigin"];
if( originString ) {
CGPoint origin = CGPointFromString(originString);
self.frame = CGRectMake(origin.x, origin.y, self.frame.size.width, self.frame.size.height);
}
( - ) . , , prefs, , , "" UIView ( ), , , ).
№ 2
, frame. Apple http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW6 ( ):
, . frame, , .
№ 3
, , prefs, . bounds rect {{0, 0}, {506, 254}}. VD viewDidLoad - . , , bounds - - . : {{0, 0}, {488.321, 435.981}} ( , , ). reset , , .
reset , , , ! viewDidLoad, bounds - .
EDIT # 4
self.bounds initWithCoder ( NIB), layoutSubviews, self.bounds CGRect. .
. . ( ?) Skram , , .