Periscope self-made mad heart of Hearts
Foreign iOS App "Periscope" very fire, watch mobile video live, click anywhere on the screen, the bottom right corner of the screen can be floated out of a variety of colors of hearts, the effect is very dazzling!
For this I made a code that imitates Periscope hearts:
-(void) startlittleheartshow{
//Construct a small peach heart uiimageview, in which the color of hearts can be randomly changed
float fcolorredbase = random()%/10.0;
float fcolorgreenbase = random()%5/10.0;
float fcolorbluebase = random()%5/10.0;
float falphabase = 1.0 - random()%7/10.0;
//The color of the Little peach Heart
uicolor* Heartcolor = [[uicolor alloc] initwithred: fcolorredbase Green : Fcolorgreenbase Blue: fcolorbluebase Alpha: falphabase];
//Fill in a random color to UIImage's heart image
UIImage* flakeimage = [[UIImage imagenamed:@ "Pooheart.png"] Imagewithtintcolor : Heartcolor];
Uiimageview* Flakeview = [[uiimageview alloc] initwithimage: flakeimage];
float fxbase = heart_bk_view_width/2;//heart_bk_view_width is the width of the form VIEW
float fybase = heart_bk_view_height;//heart_bk_view_height is the height of the form VIEW
//Set small peach Heart Animation starting point, X position to the right randomly offset 0~19
long lrandom = random();
int StartX = fxbase+lrandom%;
int starty = fybase;
//Set small peach Heart Animation end point, X position left and right offset 0~74
int endx = ((lrandom%2) = =0)? (startx-lrandom%): (StartX + lrandom%);
double scale = 1 / round(random()% ) + 1.0;//Set the random offset of the hearts size, So the size of the peach heart can be different.
Double Speed = 1 / round(random()% ) + 1.0;// Set the speed offset of the heart flight so that each peach heart can fly out of the same speed
Scale = (Scale > 1.5)? 1.5 : scale;
Flakeview. frame = CGRectMake(StartX, Starty, 25.0 * scale, 25.0 * scale);//Initialize the hearts of the frame
@try {
//Add the heart to the main view, note that after the animation is complete, you need to remove the peach from the main view.
[self. View addsubview: Flakeview];
[UIView beginanimations:nil Context:(__bridge void *) ( Flakeview)];
//Set the time for the heart to fly, that is, the speed of its flight
float fspeedbase = random()%5;
Fspeedbase = (Fspeedbase < 3.0)? 3.0 : fspeedbase;
float fduration = fspeedbase * speed;
Fduration = (Fduration > 5.0)? 5.0 : fduration;
Fduration = (fduration <= 0)? 2.5 : fduration;
Fduration = fduration- 1;
[UIView setanimationduration: fduration];
//Set the flying end of Peach heart!
Flakeview. frame = CGRectMake(endx, fybase-heart_bk_view_height-random()%, 25.0 * scale, 25.0 * scale);
//Set the callback function at the end of the Hearts animation, you need to remove Flakeview in callback Self.view
[UIView setanimationdidstopselector:@selector(onAnimationComplete:finished:context:)];
[UIView setanimationdelegate:self];
[UIView commitanimations]; Start animation
}
@catch (nsexception *exception) {
NSLog(@ "Startloveshow exception ...");
}
}
After the animation is finished, remove the Flakeview from the Onanimationcomplete function
-(void) Onanimationcomplete: (nsstring *) Animationid finished: (nsnumber *) finished Context: (void *) context {
uiimageview *flakeview = (__bridge uiimageview *) (context);
Flakeview. Hidden = YES;
[Flakeview Removefromsuperview];
}
Finally put in a full-screen click event, you can, click anywhere can be a peach heart
-(void) touchesended: (nsset *) touches withevent: (uievent *) event {
[self startloveshow];
}
"Easy Version" iOS faux periscope homemade crazy hearts