Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/extensions/Variables/includes/ExtVariables.php on line 198
UIView: Difference between revisions - iPhone Development Wiki

UIView: Difference between revisions

From iPhone Development Wiki
mNo edit summary
m (Improved accuracy and grammar.)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[UIView]] is the root class of all UI elements.  
[[UIView]] is a relatively light wrapper around CALayer. It is the root class of all elements displayed on the screen.


== Undocumented methods ==
== Getting View Hierarchy Info ==
There are two ways of getting the view hierarchy info, the "human readable" <tt>-[UIView recursiveDescription]</tt> and "machine readable" <tt>-[UIView scriptingInfoWithChildren]</tt>.


=== -recursiveDescription ===
=== -recursiveDescription ===
{{Function signature
{{Function signature
|signature=-(NSString*)recursiveDescription;
|signature=-(NSString*)recursiveDescription;
|firmware=3.0 – 3.1
|firmware=3.0 –
}}
}}
Returns the description of the view and its subviews.
Returns the description of the view and its subviews.
Line 20: Line 21:
{{Function signature
{{Function signature
|signature=-(NSDictionary*)scriptingInfoWithChildren;
|signature=-(NSDictionary*)scriptingInfoWithChildren;
|firmware=2.0 – 3.1
|firmware=2.0 –
}}
}}


This function returns an NSDictionary with contains some information e.g. geometry, class name, etc.
This function returns an NSDictionary with contains some information e.g. geometry, class name, etc.
== Animation Blocks ==
{{see|UIViewAnimationState}}
[http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW11 Animation blocks] are implemented by the UIViewAnimationState class with the following correspondences:
{| class="wikitable"
|-
! UIView methods
! Equivalent call
|-
| <tt>[UIView beginAnimations:</tt>''identifier''<tt> context:</tt>''context''<tt>];</tt>
| <tt>[UIViewAnimationState pushViewAnimationState:</tt>''identifier''<tt> context:</tt>''context''<tt>];</tt>
|-
| <tt>[UIView commitAnimations];</tt>
| <tt>[UIViewAnimationState popAnimationState];</tt>
|-
| <tt>[UIView setAnimationStartDate:</tt>''date''<tt>];</tt>
| <tt>__currentViewAnimationState->_start = [</tt>''date''<tt> timeIntervalSinceReferenceDate];</tt>
|-
| <tt>[UIView setAnimationsEnabled:</tt>''enabled''<tt>];</tt>
| <tt>__animate = </tt>''enabled''<tt>;</tt>
|-
| <tt>[UIView setAnimationDelegate:</tt>''delegate''<tt>];</tt>
| <tt>if (__currentViewAnimationState->_delegate != </tt>''delegate''<tt>) {<br />&nbsp; [__currentViewAnimationState->_delegate release];<br />&nbsp; __currentViewAnimationState->_delegate = [</tt>''delegate''<tt> retain];<br />}</tt>
|-
| <tt>[UIView setAnimationWillStartSelector:</tt>''selector''<tt>];</tt>
| <tt>__currentViewAnimationState->_willStartSelector = </tt>''selector''<tt>;</tt>
|-
| <tt>[UIView setAnimationDidStopSelector:</tt>''selector''<tt>];</tt>
| <tt>__currentViewAnimationState->_didEndSelector = </tt>''selector''<tt>;</tt>
|-
| <tt>[UIView setAnimationDuration:</tt>''duration''<tt>];</tt>
| <tt>__currentViewAnimationState->_duration = </tt>''duration''<tt>;</tt>
|-
| <tt>[UIView setAnimationDelay:</tt>''delay''<tt>];</tt>
| <tt>__currentViewAnimationState->_delay = </tt>''delay''<tt>;</tt>
|-
| <tt>[UIView setAnimationCurve:</tt>''curve''<tt>];</tt>
| <tt>__currentViewAnimationState->_curve = </tt>''curve''<tt>;</tt>
|-
| <tt>[UIView setAnimationRepeatCount:</tt>''repeatCount''<tt>];</tt>
| <tt>__currentViewAnimationState->_repeatCount = </tt>''repeatCount''<tt>;</tt>
|-
| <tt>[UIView setAnimationRepeatAutoreverses:</tt>''autoreverses''<tt>];</tt>
| <tt>__currentViewAnimationState->_autoreverses = </tt>''autoreverses''<tt>;</tt>
|-
| <tt>[UIView setAnimationBeginsFromCurrentState:</tt>''value''<tt>];</tt>
| <tt>__currentViewAnimationState->_useCurrentLayerState = </tt>''value''<tt>;</tt>
|-
| <tt>[UIView setAnimationTransition:</tt>''transVal''<tt> forView:</tt>''container''<tt> cache:</tt>''cache''<tt>];</tt>
| <tt>__currentViewAnimationState->_transition = </tt>''transVal''<tt>;<br />__currentViewAnimationState->_transitionView = [</tt>''container''<tt> retain];<br />__currentViewAnimationState->_cacheTransition = </tt>''cache''<tt>;</tt>
|-
| <tt>[UIView areAnimationsEnabled];</tt>
| <tt>__animate;</tt>
|}
In above, <tt>__currentViewAnimationState</tt> is a global variable, which is a [[UIViewAnimationState]]. This value is automatically updated after calling <tt>+pushViewAnimationState:context:</tt> and <tt>+popAnimationState</tt>. NULL checks were omitted in the above codes for simplicity.
There are also a few undocumented methods:
{| class="wikitable"
|-
! UIView method
! Equivalent call
|-
| <tt>[UIView beginAnimations:</tt>''identifier''<tt>];</tt>
| <tt>[UIView beginAnimations:</tt>''identifier''<tt> context:NULL];</tt>
|-
| <tt>[UIView setAnimationPosition:</tt>''position''<tt>];</tt>
| <tt>__currentViewAnimationState->_position = </tt>''position''<tt>;</tt>
|-
| <tt>[UIView disableAnimation];</tt>
| <tt>__animate = NO;</tt>
|-
| <tt>[UIView enableAnimation];</tt>
| <tt>__animate = YES;</tt>
|-
| <tt>[UIView setAnimationFrameInterval:</tt>''interval''<tt>];</tt>
| <tt>__currentViewAnimationState->_frameInterval = </tt>''interval''<tt>;</tt>
|-
| <tt>[UIView setAnimationStartTime:</tt>''time''<tt>];</tt>
| <tt>__currentViewAnimationState->_start = </tt>''time''<tt>;</tt>
|-
| <tt>[UIView setAnimationRoundsToInteger:</tt>''rounds''<tt>];</tt>
| <tt>__currentViewAnimationState->_roundsToInteger = </tt>''rounds''<tt>;</tt>
|-
| <tt>[UIView _isInAnimationBlock];</tt><ref><tt>+_isInAnimationBlock</tt> was named as <tt>+_pendingAnimations</tt> prior to 3.2</ref>
| <tt>__currentViewAnimationState != nil;</tt>
|-
| <tt>[UIView _setAnimationAttributes:</tt>''attr''<tt>];</tt><ref name="3.2">These methods are available since 3.2.</ref>
| <tt>[__currentViewAnimationState setAnimationAttributes:</tt>''attr''<tt>];</tt>
|-
| <tt>[UIView _setAnimationFilter:</tt>''filter''<tt> forView:</tt>''view''<tt>];</tt><ref name="3.2"/>
| <tt>__currentViewAnimationState-&gt;_filter = </tt>''filter''<tt>;<br />__currentViewAnimationState-&gt;_filterView = [</tt>''view''<tt> retain];</tt>
|-
| <tt>[UIView _setAnimationFilterValue:</tt>''value''<tt>];</tt><ref name="3.2"/>
| <tt>__currentViewAnimationState-&gt;_filterValue = </tt>''value''<tt>;</tt>
|}
There are also a few equivalent (probably deprecated) selectors:
{| class="wikitable"
|-
! Selector !! Equivalent to
|-
| <tt>+endAnimations</tt> || <tt>+commitAnimations</tt>
|-
| <tt>+setAnimationAutoreverses:</tt> || <tt>+setAnimationRepeatAutoreverses:</tt>
|-
| <tt>+setAnimationFromCurrentState:</tt> || <tt>+setAnimationBeginsFromCurrentState:</tt>
|}
== frame and bounds ==
<tt>frame</tt> and <tt>bounds</tt> are both properties of a UIView. When the view's <tt>transform</tt> is not identity, the only difference between them is the origin of <tt>bounds</tt> is always zero.
When <tt>transform</tt> is ''not'' identity, the SDK documentation warns that <tt>frame</tt> is undefined:
{{cquote|'''Warning:''' If the <tt>transform</tt> property is not the identity transform, the value of this property is undefined and therefore should be ignored.}}
However, this is not completely true — the <tt>frame</tt> is actually the rectangle enclosing the ''transformed'' view.
These properties are actually proxies to the corresponding ones of [[CALayer]]. However, while the <tt>bounds</tt> (and <tt>center</tt>) is an internal property, <tt>frame</tt> incurs a transactional lock (spin lock) and an affine transform.


== References ==
== References ==
* Official documentation: http://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html
<references />
* Additional header: http://github.com/kennytm/iphone-private-frameworks/blob/master/UIKit/UIView2.h
* Official documentation: {{sdklink|UIKit|UIView}}
 
{{IPFHeader|UIKit|3=2}}
{{occlass|library=UIKit.framework|navbox=on}}

Latest revision as of 02:39, 29 September 2013

UIView is a relatively light wrapper around CALayer. It is the root class of all elements displayed on the screen.

Getting View Hierarchy Info

There are two ways of getting the view hierarchy info, the "human readable" -[UIView recursiveDescription] and "machine readable" -[UIView scriptingInfoWithChildren].

-recursiveDescription

Signature -(NSString*)recursiveDescription;
Available in 3.0 –

Returns the description of the view and its subviews.

Example output:

<UIWebView: 0x4116bb0; frame = (0 100; 320 230); layer = <CALayer: 0x4116c20>>
   <UIScroller: 0x411e110; frame = (0 0; 320 230); clipsToBounds = YES; autoresize = H; layer = <CALayer: 0x411e4d0>>
       <UIImageView: 0x411f460; frame = (0 0; 54 54); transform = [-1, 0, -0, -1, 0, 0]; alpha = 0; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x411f490>>
       <UIWebDocumentView: 0x4812c00; frame = (0 0; 320 230); layer = <UIWebLayer: 0x41171c0>>

-scriptingInfoWithChildren

Signature -(NSDictionary*)scriptingInfoWithChildren;
Available in 2.0 –

This function returns an NSDictionary with contains some information e.g. geometry, class name, etc.

Animation Blocks

Animation blocks are implemented by the UIViewAnimationState class with the following correspondences:

UIView methods Equivalent call
[UIView beginAnimations:identifier context:context]; [UIViewAnimationState pushViewAnimationState:identifier context:context];
[UIView commitAnimations]; [UIViewAnimationState popAnimationState];
[UIView setAnimationStartDate:date]; __currentViewAnimationState->_start = [date timeIntervalSinceReferenceDate];
[UIView setAnimationsEnabled:enabled]; __animate = enabled;
[UIView setAnimationDelegate:delegate]; if (__currentViewAnimationState->_delegate != delegate) {
  [__currentViewAnimationState->_delegate release];
  __currentViewAnimationState->_delegate = [
delegate retain];
}
[UIView setAnimationWillStartSelector:selector]; __currentViewAnimationState->_willStartSelector = selector;
[UIView setAnimationDidStopSelector:selector]; __currentViewAnimationState->_didEndSelector = selector;
[UIView setAnimationDuration:duration]; __currentViewAnimationState->_duration = duration;
[UIView setAnimationDelay:delay]; __currentViewAnimationState->_delay = delay;
[UIView setAnimationCurve:curve]; __currentViewAnimationState->_curve = curve;
[UIView setAnimationRepeatCount:repeatCount]; __currentViewAnimationState->_repeatCount = repeatCount;
[UIView setAnimationRepeatAutoreverses:autoreverses]; __currentViewAnimationState->_autoreverses = autoreverses;
[UIView setAnimationBeginsFromCurrentState:value]; __currentViewAnimationState->_useCurrentLayerState = value;
[UIView setAnimationTransition:transVal forView:container cache:cache]; __currentViewAnimationState->_transition = transVal;
__currentViewAnimationState->_transitionView = [
container retain];
__currentViewAnimationState->_cacheTransition =
cache;
[UIView areAnimationsEnabled]; __animate;

In above, __currentViewAnimationState is a global variable, which is a UIViewAnimationState. This value is automatically updated after calling +pushViewAnimationState:context: and +popAnimationState. NULL checks were omitted in the above codes for simplicity.

There are also a few undocumented methods:

UIView method Equivalent call
[UIView beginAnimations:identifier]; [UIView beginAnimations:identifier context:NULL];
[UIView setAnimationPosition:position]; __currentViewAnimationState->_position = position;
[UIView disableAnimation]; __animate = NO;
[UIView enableAnimation]; __animate = YES;
[UIView setAnimationFrameInterval:interval]; __currentViewAnimationState->_frameInterval = interval;
[UIView setAnimationStartTime:time]; __currentViewAnimationState->_start = time;
[UIView setAnimationRoundsToInteger:rounds]; __currentViewAnimationState->_roundsToInteger = rounds;
[UIView _isInAnimationBlock];[1] __currentViewAnimationState != nil;
[UIView _setAnimationAttributes:attr];[2] [__currentViewAnimationState setAnimationAttributes:attr];
[UIView _setAnimationFilter:filter forView:view];[2] __currentViewAnimationState->_filter = filter;
__currentViewAnimationState->_filterView = [
view retain];
[UIView _setAnimationFilterValue:value];[2] __currentViewAnimationState->_filterValue = value;

There are also a few equivalent (probably deprecated) selectors:

Selector Equivalent to
+endAnimations +commitAnimations
+setAnimationAutoreverses: +setAnimationRepeatAutoreverses:
+setAnimationFromCurrentState: +setAnimationBeginsFromCurrentState:

frame and bounds

frame and bounds are both properties of a UIView. When the view's transform is not identity, the only difference between them is the origin of bounds is always zero.

When transform is not identity, the SDK documentation warns that frame is undefined:

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

However, this is not completely true — the frame is actually the rectangle enclosing the transformed view.

These properties are actually proxies to the corresponding ones of CALayer. However, while the bounds (and center) is an internal property, frame incurs a transactional lock (spin lock) and an affine transform.

References

  1. +_isInAnimationBlock was named as +_pendingAnimations prior to 3.2
  2. 2.0 2.1 2.2 These methods are available since 3.2.