我试图在Facebook的照片集合视图中显示这种效果:
我的目标是:
我已经完成了淡出工作,但动画效果最差.
我的CollectionView:
import UIKit
class Feed: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
var collectionView: UICollectionView?
var myArray = ["cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun", "cool", "neat", "fun"]
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.yellowColor()
self.title = "Feed"
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
layout.itemSize = …Run Code Online (Sandbox Code Playgroud) 在使用 AVFoundation 和 AVCamRecorder 录制电影后,我正在推送一个新的 UIViewController。
目前我正在从保存电影的 URL 播放电影,并且工作正常。我在理解如何将视频从 URL 转换为动画 gif 时遇到了很多麻烦。
我是相当新的,以目标C和有成功创建一个漂亮的自定义视频录像机,但现在我不鼓励这个下一条。
我有
第二视图控制器.h
@interface SecondViewController : UIViewController
@property NSURL *videoURL;
@end
Run Code Online (Sandbox Code Playgroud)
第二视图控制器.m
#import "SecondViewController.h"
#import "FirstViewController.h"
#import "CaptureManager.h"
#import "AVCamRecorder.h"
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface SecondViewController ()
@property (nonatomic, strong) CaptureManager *grabFile;
@property (nonatomic, strong) MPMoviePlayerController *movie;
@end
@implementation SecondViewController
- (void)viewDidLoad
{
self.movie = [[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
_movie.view.frame = CGRectMake(0.0, 64.0, 320.0, 320.0);
_movie.movieSourceType = MPMovieSourceTypeFile;
_movie.repeatMode = MPMovieRepeatModeOne;
[self.view addSubview:_movie.view];
[_movie play];
} …Run Code Online (Sandbox Code Playgroud) 怎么会在Swift中写这个?
更新:发布我正在尝试转换的方法,最初发布了一个不同于我试图隐藏的方法
这适用于Objective C,但不适用于Swift.我得到的转换错误,当我尝试使用ceilf,并floorf用CGFloat.
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
float pageWidth = 200 + 30; // width + space
float currentOffset = scrollView.contentOffset.x;
float targetOffset = targetContentOffset->x;
float newTargetOffset = 0;
if (targetOffset > currentOffset)
newTargetOffset = ceilf(currentOffset / pageWidth) * pageWidth;
else
newTargetOffset = floorf(currentOffset / pageWidth) * pageWidth;
if (newTargetOffset < 0)
newTargetOffset = 0;
else if (newTargetOffset > scrollView.contentSize.width)
newTargetOffset = scrollView.contentSize.width;
targetContentOffset->x = currentOffset; …Run Code Online (Sandbox Code Playgroud) 我有以下方法:
- (void) savePhotoToUser {
NSData *imageData = UIImageJPEGRepresentation(_imgView.image, 1.0);
PFFile *imageFile = [PFFile fileWithName:@"img.png" data:imageData];
[imageFile saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
//THIS IS WHERE I NEED HELP
//
PFObject *userPhoto = [PFObject objectWithClassName:@"User"];
//
//
[userPhoto setObject:imageFile forKey:@"profilePicture"];
[userPhoto saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(@"Saved %@ for user %@", imageFile, userPhoto);
//Push ViewController
}
else{
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
else{
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}]; …Run Code Online (Sandbox Code Playgroud) objective-c ×3
ios ×2
swift ×2
xcode ×2
animated-gif ×1
avfoundation ×1
iphone ×1
scrollview ×1