iphone - Rotation Animation on UIImageView -
i have sunrays image. put on background , make rotate continuosly in slow motion..
the image this..
i've tried rotating cabasicanimation, rotates whole frame.. want sunrays revolve @ background not whole frame..
is there way it???
update:
here m doing...please point out mistakes... :(
i didn't got wat u've explained.. :(
here m doing...
- (void)viewdidload { sunrayscontainer = [[uiview alloc] initwithframe:cgrectmake(0, 0, 1024, 768)]; sunrayscontainer.clipstobounds = yes; [self.view addsubview:sunrayscontainer]; sunrays = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, 1024, 768)]; [sunrays setimage:[uiimage imagenamed:@"sunlight-background copy2.jpg"]]; [sunrayscontainer addsubview:sunrays]; backgroundbuilding = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, 1024, 768)]; [backgroundbuilding setimage:[uiimage imagenamed:@"hira-background_fade.png"]]; [sunrayscontainer addsubview:backgroundbuilding]; [uiview beginanimations:nil context:nil]; [uiview setanimationduration:5]; cabasicanimation *rotationanimation; rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; rotationanimation.tovalue = [nsnumber numberwithfloat:m_pi * 2.0 * 4.0]; rotationanimation.duration = 1; rotationanimation.cumulative = yes; rotationanimation.repeatcount = 10; rotationanimation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; [sunrays.layer addanimation:rotationanimation forkey:@"rotationanimation"]; [uiview commitanimations]; }
update...
i did u said nacho...thanks reply,but m getting blankscreen.. :(
i've coded dis...
sunrays = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"sunlight-background copy2.jpg"]]; uiview *container = [[uiview alloc] initwithframe:cgrectmake(0,0,sunrays.frame.size.height,sunrays.frame.size.height)]; [container setclipstobounds:yes]; [container addsubview:sunrays]; [sunrays setcenter:cgpointmake(container.bounds.size.width/2, container.bounds.size.height/2)]; [uiview beginanimations:nil context:nil]; [uiview setanimationduration:5]; cabasicanimation *rotationanimation; rotationanimation = [cabasicanimation animationwithkeypath:@"transform.rotation.z"]; rotationanimation.tovalue = [nsnumber numberwithfloat:m_pi * 2.0 * 4.0]; rotationanimation.duration = 1; rotationanimation.cumulative = yes; rotationanimation.repeatcount = 10; rotationanimation.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseout]; [sunrays.layer addanimation:rotationanimation forkey:@"rotationanimation"]; [uiview commitanimations];
what wrong wid code??
well think should generate different images , try animate this
imgloading.animationimages = [nsarray arraywithobjects: [uiimage imagenamed:@"img1.png"] [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:30.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:60.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:90.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:120.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:150.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:180.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:210.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:240.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:270.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:300.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:330.0]], [uiimage imagewithcgimage: [self cgimagerotatedbyangle: [[uiimage imagenamed:@"img1.png"] cgimage]angle:360.0]], nil]; imgloading.animationrepeatcount=0; imgloading.animationduration=.5; [imgloading startanimating];
in above code have added images separately can populate them in loop.
- (cgimageref)cgimagerotatedbyangle:(cgimageref)imgref angle:(cgfloat)angle
{
cgfloat angleinradians = angle * (m_pi / 180); cgfloat width = cgimagegetwidth(imgref); cgfloat height = cgimagegetheight(imgref); cgrect imgrect = cgrectmake(0, 0, width, height); cgaffinetransform transform = cgaffinetransformmakerotation(angleinradians); cgrect rotatedrect = cgrectapplyaffinetransform(imgrect, transform); cgcolorspaceref colorspace = cgcolorspacecreatedevicergb(); cgcontextref bmcontext = cgbitmapcontextcreate(null, rotatedrect.size.width, rotatedrect.size.height, 8, 0, colorspace, kcgimagealphapremultipliedfirst); cgcontextsetallowsantialiasing(bmcontext, yes); cgcontextsetshouldantialias(bmcontext, yes); cgcontextsetinterpolationquality(bmcontext, kcginterpolationhigh); cgcolorspacerelease(colorspace); cgcontexttranslatectm(bmcontext, +(rotatedrect.size.width/2), +(rotatedrect.size.height/2)); cgcontextrotatectm(bmcontext, angleinradians); cgcontexttranslatectm(bmcontext, -(rotatedrect.size.width/2), -(rotatedrect.size.height/2)); cgcontextdrawimage(bmcontext, cgrectmake(0, 0, rotatedrect.size.width, rotatedrect.size.height), imgref); cgimageref rotatedimage = cgbitmapcontextcreateimage(bmcontext); cfrelease(bmcontext); [(id)rotatedimage autorelease]; return rotatedimage;
}
the above function can used give rotated images..
Comments
Post a Comment