페이지

2012년 11월 10일 토요일

Core Animation Programming Summary 2


Animation


The animation occurs automatically in a separate thread, without further interaction with your application.

Animation Classes and Timing

- CABasicAnimation
- CAKeyframeAnimation
- CATransition
- CAAnimationGroup

Implicit Animation

Implicitly animating multiple properties of multiple layers
theLayer.opacity = 0.0;
theLayer.zPosition = -100;


Explicit Animation


ex 1 
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration = 3.0;
theAnimation.repeatCount = 2;
theAnimation.autoreverse = YES;
theAnimation.fromValue = [NSNumber numberWithFloat:1.0];
theAnimation.toValue = [NSNumber numberWithFloat:0.0];
[theLayer addAnimation:theAnimation forKey:@"animateOpacity"];

ex 2

CIFileter *filter = [CIFilter filterWithName:@"CIBloom"];
[filter setDefaults];
[filter setValue:[NSNumber numberWithFloat:5.0] forKey:@"inputRadius"];
[filter setName:@"pulseFilter"];
[selectionLayer setFilters:[NSArray arrayWithObject:filter]];
CABasicAnimation* pulseAnimation = [CABasicAnimation animation];
pulseAnimation.keyPath = @"filters.pulseFilter.inputIntensity";
pulseAnimation.fromValue = [NSNumber numberWithFloat:0.0];
pulseAnimation.toValue = [NSNumber numberWithFloat:1.5];
pulseAnimation.duration = 1.0;
pulseAnimation.repeatCount = HUGE_VALF;
pulseAnimation.autoreverses = YES;
pulseAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[selectionLayer addAnimation:pulseAnimation forKey:@"pulseAnimation"];


Starting and Stopping Explicit Animations

addAnimation:forKey:
removeAnimationForKey:
removeAllAnimations


Layer Actions


A Layer is responsible for mapping action identifiers to the appropriate action objects.
typically, action objects are an instance of a CAAnimation subclass, which implements the CAAction protocol.
When an instance of CAAnimation receives the runActionForKey:object:arguments: message it responds by adding itself to the layer's animations

The Role of Action Objects
?
Defined Search Pattern for Action Keys
?
Adopting the CAAction Protocol
?
- (void) runActionForKey:(NSString*)key
object:(id)anObject
arguments:(NSDictionary*)dict
{
[(CALayer*)anObject addAnimation:self forKey:key];
}


Overriding an Implied Animation


- (id<CAAction>)actionForLayer:(CALayer*)theLayer
forKey:(NSString*)theKey
{
CATransition *theAnimation = nil;
if ([theKey isEqualToString:@"contents"])
{
theAnimation = [[CATransition alloc] init];
theAnimation.duration = 1.0;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
theAnimation.type = kCATransitionPush;
theAnimation.subtype = kCATransitionFromRight;
}
return theAnimation;
}



Implied animation for the sublayers property


NSMutableDictionary *customActions = [NSMutableDictionary dictionaryWithDictionary:[theLayer actions]];
//diable the animation for the sublayers property
[customActions setObject:[NSNull null] forKey:@"sublayers"];
theLayer.actions = customActions;



Transactions


Implicit transactions

theLayer.opacity = 0.0;
theLayer.zPosition = -200;
theLayer.position = CGPointMake(0.0, 0.0);

Explicit transactions

Explicit transactions are particularly useful when setting the properties of many layers at the same time (for example, while laying out multiple layers)

Temporarily disabling a layer's actions

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
forKey:kCATransactionDisableActions];
[aLayer removeFromSuperlayer];
[CATranscation commit];



Overriding the animation duration

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:10.0f]
forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit];


Nesting explicit transactions

[CATransaction begin]; //outer transaction
//change the animation duration to 2 secs
[CATransaction setValue:[NSNumber numberWithFloat:2.0f]
forKey:kCATransactionAnimationDuration];
theLayer.position = CGPointMake(0.0, 0.0);
[CATransaction begin]; //inner transaction
[CATransaction setValue:[NSNumber numberWithFloat:5.0f]
forKey:kCATransactionAnimationDuration];
theLayer.zPosition = 200.0;
theLayer.opacity = 0.0;
[CATransaction commit]; //inner transaction
[CATransaction commit]; //outer transaction



Laying Out Core Animation Layers

Contraints Layout Manager

Default Value Support

+(id)defaultValueForKey:(NSString*) key
{
if ( [key isEqualToString:@"masksToBounds"] )
return [NSNumber numberWithBool:YES];
return [super defaultValueForKey:key];
}



myLayer.transform.rotation.x = 0; // this is wrong
[myLayer setValue:[NSNumber numberWithInt:0] forKeyPath:@"transform.rotation.x"];
//this is right.

2012년 11월 4일 일요일

Core Animation Programming Guide Summary


Core animation classes

- Layer classes that provide content for display
- Animation and timing classes
- Layout and constraint classes
- A transaction class that groups multiple layer changes into an atomic update

Layer classes

CALayer is the parent class for all types of Core animation layers.
CALayer diverges from the application kit and cocoa touch view classes in that it's not necessary to subclass CALayer in order to display content.

Animation and Timing Classes

CAAnimation adopts CAMediaTiming protocol which provides the simple duration,speed and repeat count for an animation.
and adopts CAAction protocol.

- CATransition
- CAAnimationGroup
- CAPropertyAnimation
- CABasicAnimation 
- CAKeyframeAnimation

Layout Manager Classes

- CAContraint

Transaction Management Classes


Core Animation Rendering Architecture
NSView,UIView are objects in the MVC pattern.
Core Animation Layers are model objects.
the actual display is not the layer's responsibility.

a presentation tree and a render tree.

layer-tree -> Presentation-tree -> Render-tree (Private)




Layer-tree Hierarchy


Displaying Layers in Views

[theView setLayer: theRootLayer];
[theView setWantsLayer:YES];

Adding,Removing Layers from a Hierarchy
while inserting,removing,replacing layers cause kCAOnOrderIn, kCAOnOrderOut, kCATransition triggered.

Repositioning and Resizing Layers
If a layer's needsDisplayOnBoundsChange property is YES, the layer's content is recached when the layer's bounds changes. this value is no by default.

Autoresizing Layers
CAAutoresizingMask

Clipping Sublayers
masksToBounds determines if sublayers are clipped to the parent.

Providing Layer Content

When using Cocoa views you must subclass NSVIew or UIView and implement drawRect: in order to display anything. However CALayer instances can often be used directly, without requiring subclassing. Because CALayer is a key-value coding compliant container class, that is you can store arbitrary values in any instance, subclassing can often be avoided entirely.

Providing CALayer Content

- Explicitly set the contents property of a layer instance using a CGImageRef that contains the content image.
- Specify a delegate that provides, or draws, the content.
- Subclass CALayer and override one of the display methods.

Setting the Contents Property
CALayer *theLayer;
theLayer = [CALayer layer];
theLayer.position = CGPointMake(50,50);
theLayer.bounds = CGRectMake(0,0,100,100);
theLayer.contents = theImage; //CGImageRef

Using a Delegate to Provide Content
displayLayer: or drawLayer:inContext: are called by sending it a setNeedsDisplay or setNeedsDisplayInRect: or needsDisplayOnBoundsChange = YES.

Subclassing is not required to store the state value, coz the CALayer instance acts as a key-value coding container.
- (void)displayLayer:(CALayer*)theLayer
{
if ([[theLayer valueForKey:@"state"] boolValue])
{
theLayer.contents = [someHelperObject loadStateYesImage];
}
else {
theLayer.contents = [someHelperObject loadStateNoImage];
}
}



if you must the layer's content rather than loading it from an image, use drawLayer:inContext:
- (void)drawLayer:(CALayer*)theLayer inContext:(CGContextRef)theContext
{
CGMutablePathRef thePath = CGPathCreateMutable();
CGPathMoveToPoint( thePath,NULL,15.0f,15.f);
CGPathAddCurveToPoint( thePath, NULL, 15.f,250.f,295.f,250.f,295.f,15.f );
CGContextBeginPath(theContext);
CGContextAddPath(theContext, thePath);
CGContextSetLineWidth( theContext, [[theLayer valueForKey:@"lineWidth"] floatValue]);
CGContextStokePath(theContext);
CFRelease(thePath);
}


Providing CALayer Content by Subclassing

using property rather than depending on the key-value coding container.
- (void)display{ if(self.state) { self.contents = [someHelperObject loadStateYesImage]; } else { self.contents = [someHelperObject loadStateNoImage]; }}
- (void)drawInContext:(CGContextRef)theContext{ CGMutablePathRef thePath = CGPathCreateMutable(); CGPathMoveToPoint(thePath,NULL,15.f,15.f); CGPathAddCurveToPoint(thePath,NULL,15.f,250.f,295.f,250.f,295.f,15.f); CGContextBeginPath(theContext); CGContextAddPath(theContext, thePath); CGContextSetLineWidth(theContext,self.lineWidth); CGContextSetStrokeColorWithColor(theContext, self.lineColor); CGContextStrokePath(theContext); CFRelease(thePath);}


Positioning Content Within a Layer

contentsGravity property allows you to position and scale the layer's contents image within the layer bounds. by default, the content image fills the layer's bounds entirely, ignoring the natural aspect ratio of the image.



2012년 10월 4일 목요일

if we added more codes in setter/getter methods, we must override them by ourself in inherited class.


if we added more codes in setter/getter methods, we must override them by ourself in inherited class.


@interface ParentClass:NSObject
@property (nonatomic) int type;
- (void)updateData;
@end

@implentation ParentClass
@synthesize type = _type;

- (void) setType:(int) pType {
    _type = pType;
    
    [self doSomething];   //added codes
}

- (void) updateData
{
    self.type ++;
    NSLog("%d",self.type);
}
- (void) doSomething
{
    NSLog(@"ParentClass:doSomething called!!");
}
@end





@interface ChildClass: ParentClass
@end

@implementation ChildClass
@synthesize type = _type;

- (void) updateData {
    [super updateData];    // doSomething is not called!!
}
- (void) doSomething
{
   NSLog(@"ChildClass:doSomething called!!");
}
@end




changed this.

@implementation ChildClass
@synthesize type = _type;


- (void) setType:(int) pType {
    _type = pType;
    
    [self doSomething];
}


- (void) updateData {
    [super updateData];    // doSomething is called
}

- (void) doSomething
{
   NSLog(@"ChildClass:doSomething called!!");
}

@end





coz, @synthesize make default setter/getter methods by itself. so these methods are different from them that you implemented in super class.


2012년 9월 25일 화요일

Objective-C setter method


@property(nonatomic,retain) NSObject * exVal;

@synthesize exVal;

- (void)setExVal:(NSObject*) val {
   [exVal release]; 
   exVal = [val retain];
}




this is wrong. coz if val is equal to exVal, both exVal and val are released. and then nil retain.






- (void)setExVal:(NSObject*) val {
    [val retain];
    [exVal release];
    exVal = val;
}

this is right.


2012년 9월 11일 화요일

Big Endian, Little Endian

Big Endian, Little Endian

I sometimes got confused about these.
What is big or little?
and
What is Endian?

I will try to figure these out at this time.

------------------------
big, little : the value of byte
endian : the end of memory that occupied by the value in row.


so, Big endian means that Big value of byte is located in the end of memory.



http://en.wikipedia.org/wiki/Endianness

2012년 9월 9일 일요일

php - go to other page



<!-- go to other page by button -->
<input type="button" value="go list" onClick="location.href='simple_list.php'">

<!-- go to other page by hypertext -->
<td colspan="4" align="center"><a href="simple_insert.html"> insert </a> </td>

php - script alert, history.back


<?
if(!$id){
echo " <script> alert(' please, input id'); history.back();</script>";
exit;
}
?>

php - form



<form name="frm" method="post" action="simple_delete.php'">
<input type="submit" value="delete">
</form>


<form name="frm" method="post" action="simple_delete.php?no=<?=$_GET[no]?>'">
<input type="submit" value="delete">
</form>

<form name="frm" method="post" action="simple_pwd_chk.php?no=<?=$_GET[no]?>'">
<input type="text" name="inputPwd">
<input type="submit" value="check password">
</form>

php - DB


<?
$sql = mysql_connect("localhost","user","password") or die("sql not connected". mysql_error());
mysql_select_db("db_name");
$qry = "select * from table_name";
$result = mysql_query($qry);
{
while($rows=mysql_fetch_array($result)){
echo $rows[id];
echo $rows[name];
echo $rows[phone];
}
}
{
$db_pwd = mysql_result($result,0,0); //mysql_fetch_array 보다 빠르다}
}


mysql_free_result($result);
mysql_close($sql);
?>

iOS Layer Geometry


bounds,frame,achor point, position






masksToBounds



Layer autoresizing mask constants




CALayer geometry properties



2012년 8월 19일 일요일

form send

<?
    $br = "<br>";
?>

<html>
<head><title>환경변수</title></head>
<body>
<?
    if($your_name && $your_phone){
        echo "{$your_name}님의 전화번호는 {$your_phone}입니다";
    }
   
?>
<!--
<form name = form action = "ex.php" method=post>
    post: 보내는 방식.보안에 좋음, get:보안에 않좋음.
-->

<!-- <form name = form action = "<?=$_SERVER[PHP_SELF]?>" method=post> -->
<form name = form method=post action = "ex2.html">
    <font face=굴림 size=2>
    이름 : <input type = "text" name = "your_name"> <br>
    전화 : <input type = "text" name = "your_phone"> <br>
    <input type="submit" value="send">
    </font>   
</form>


</body>
</html>


환경변수
PHP_SELF : 현 파일이름.
DOCUMENT_ROOT: 현파일의 절대경로
REMOTE_ADDR : 사용자의 IP주소

환경변수 사용시 $_SERVER 로 감싼다.
$_SERVER[REMOTE_ADDR]

php test

<?
    $br = "<br>";
?>

<?
    $file = "fopen_test.txt";
    if(file_exists($file)==false){
        echo "file not found:".$file;
        return;
    }
   
    $fp = fopen($file,r);
    if(!$fp){
        echo "failed to open";
       
    } else {
        $contents = fread($fp,filesize($file));
        echo $contents;
    }
    fclose($fp);
    echo $br;
    echo "read ok";



   
    $fp = fopen($file,a);
    if(!$fp){
        echo "failed to open";
    }else {
        $str = "append string ok추가";
        fwrite($fp,$str.$br);
        fclose($fp);
    }
    echo $br."ok! insert";   
   
?>