어떻게 완전한 iOS 생방송 앱을 신속하게 개발합니까] (좋아요 기능)
클라이언트 코드
XMGLiveOverlayViewController.m
- (IBAction)clickUpvote:(id)sender {
    
    //  
    [[SocketIOClient clientSocket] emit:@"upvote" with:@[[SocketIOClient clientSocket].roomKey]];
    
}
XMGUpVoteViewController.m
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [[SocketIOClient clientSocket] on:@"upvote" callback:^(NSArray * _Nonnull data, SocketAckEmitter * _Nonnull ack) {
       //  , 
        [self setupVoteLayer];
    }];
    
}
- (void)setupVoteLayer
{
    CALayer *layer = [CALayer layer];
    layer.contents = (id)[UIImage imageNamed:@"hearts (1)"].CGImage;
    [self.view.layer addSublayer:layer];
    layer.bounds = CGRectMake(0, 0, 30, 30);
    layer.position = CGPointMake(self.view.width * 0.5, self.view.height);
    
    [self setupAnim:layer];
}
- (void)setupAnim:(CALayer *)layer
{
    [CATransaction begin];
    
    [CATransaction setCompletionBlock:^{
        [layer removeAllAnimations];
        [layer removeFromSuperlayer];
    }];
    
    //  basic 
    CABasicAnimation *alphaAnim = [CABasicAnimation animation];
    alphaAnim.keyPath = @"alpha";
    alphaAnim.fromValue = @0;
    alphaAnim.toValue = @1;
    
    //  
    CAKeyframeAnimation *pathAnim = [CAKeyframeAnimation animation];
    pathAnim.keyPath = @"position";
    pathAnim.path = [self animPath].CGPath;
    
    
    //  
    CAAnimationGroup *group = [CAAnimationGroup animation];
    group.animations = @[alphaAnim,pathAnim];
    group.duration = 5;
    [layer addAnimation:group forKey:nil];
    
    
    
    [CATransaction commit];
}
- (UIBezierPath *)animPath
{
    UIBezierPath *path = [UIBezierPath bezierPath];
    
    CGFloat y = self.view.height;
    CGFloat x = self.view.width * 0.5;
    while (y > 0) {
        x = arc4random_uniform(self.view.width - 20) + 20;
        if (y == self.view.height) {
            [path moveToPoint:CGPointMake(x, y)];
        } else {
            [path addLineToPoint:CGPointMake(x, y)];
        }
        y -= 20;
    }
    
    
    return path;
}작가: 원봉
링크:https://www.jianshu.com/p/ac17fe0af5ae
출처: 약서
저작권은 작가의 소유이다.상업 전재는 작가에게 연락하여 권한을 얻으십시오. 비상업 전재는 출처를 밝히십시오.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
어떻게 완전한 iOS 생방송 앱을 신속하게 개발합니까] (좋아요 기능)클라이언트 코드 작은 하트를 누르면 socket을 서버에 보내고 방 키를 서버에 전달하며 어느 아나운서에게 좋아요를 누르는지 알려주면 대응하는 그룹 socket에 전송됩니다 방 키를 어떻게 전달하는지, 방 키는 아나...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.