我发现了一些关于如何UIPageViewController跳转到特定页面的问题,但我注意到跳跃的一个额外问题,没有任何答案似乎承认.
没有进入我的iOS应用程序的细节(类似于分页日历),这是我正在经历的.我声明了一个UIPageViewController,设置当前的视图控制器,并实现一个数据源.
// end of the init method
pageViewController = [[UIPageViewController alloc]
initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
options:nil];
pageViewController.dataSource = self;
[self jumpToDay:0];
}
//...
- (void)jumpToDay:(NSInteger)day {
UIViewController *controller = [self dequeuePreviousDayViewControllerWithDaysBack:day];
[pageViewController setViewControllers:@[controller]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
NSInteger days = ((THDayViewController *)viewController).daysAgo;
return [self dequeuePreviousDayViewControllerWithDaysBack:days + 1];
}
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
NSInteger days = ((THDayViewController *)viewController).daysAgo;
return [self dequeuePreviousDayViewControllerWithDaysBack:days - 1];
}
- (UIViewController *)dequeuePreviousDayViewControllerWithDaysBack:(NSInteger)days { …Run Code Online (Sandbox Code Playgroud) 我有一个用Swift写的iOS应用程序泄漏内存 - 在某些情况下应该释放一些对象,但事实并非如此.我通过简单地添加如下deinit调试消息来了解这个问题:
deinit {
println("DEINIT: KeysProvider released")
}
Run Code Online (Sandbox Code Playgroud)
因此,在应该导致对象释放的此类事件之后,deinit消息应该存在于控制台中.但是,对于应该释放的某些对象,消息将丢失.仍然,Leaks Developer Tool没有显示任何泄漏.我该如何解决这种情况?
memory-leaks memory-management ios automatic-ref-counting swift
我对使用自我内部块感到困惑,我浏览了一些Apple的文档,但仍然无法找到正确的答案.
有些人总是说在块内部使用弱自我,但有些人说在复制的块中使用弱自我,而不是总是使用.
样本1:
self.handler = ^(id response, NSError *error)
{
self.newresponse = response; //use weak self here
};
Run Code Online (Sandbox Code Playgroud)
样本2:
使用弱自我;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[weakSelf.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
//in above is it use of weak is neassary
}
completion:^(BOOL finished)
{
}];
Run Code Online (Sandbox Code Playgroud)
没有弱小的自我;
__weak myViewController *weakSelf = self;
[UIView animateWithDuration:interval delay:0.0 options:curve animations:^
{
[myViewController.view.superview setTransform:CGAffineTransformMakeTranslation(0, -106)];
}
completion:^(BOOL finished)
{
}];
Run Code Online (Sandbox Code Playgroud)
在上面的样本中,哪些是正确的......?**我正在使用ARC
我们是否需要在UIAnimation块中使用__weak self,如下所示?如果我们不指定自我弱,是否会产生保留周期问题?
[UIView animateWithDuration:animationDuration
delay:0
options:UIViewAnimationCurveEaseInOut
animations:^{
[self doSomething];
} completion:^(BOOL finished) {
if (finished) {
[self doSomething];
}
}];
Run Code Online (Sandbox Code Playgroud)
我也对以下场景感到困惑.有什么想法吗?请分享您的意见.
[self.navController dismissViewControllerAnimated:animated
completion:^{
[self doSomething];
}];
Run Code Online (Sandbox Code Playgroud)
我们应该在这里使用弱者吗?
我需要使用AVAsset对象,以便使用AVPlayer和AVPlayerLayer播放它.我开始使用Photos框架,因为不推荐使用AssetsLibrary.现在我到了我有一个PHAsset对象数组的点,我需要将它们转换为AVAsset.我尝试通过PHFetchResult枚举并使用PHAsset的本地化描述分配新的AVAsset,但是当我播放时它似乎没有显示任何视频.
PHAssetCollection *assetColl = [self scaryVideosAlbum];
PHFetchResult *getVideos = [PHAsset fetchAssetsInAssetCollection:assetColl options:nil];
[getVideos enumerateObjectsUsingBlock:^(PHAsset *asset, NSUInteger idx, BOOL *stop) {
NSURL *videoUrl = [NSURL URLWithString:asset.localizedDescription];
AVAsset *avasset = [AVAsset assetWithURL:videoUrl];
[tempArr addObject:avasset];
}];
Run Code Online (Sandbox Code Playgroud)
我假设本地化描述不是视频的绝对URL.
我还偶然发现了PHImageManager和requestAVAssetForVideo,但是,当涉及到视频时,options参数没有isSynchrounous属性,image参数就是这种情况.
PHVideoRequestOptions *option = [PHVideoRequestOptions new];
[[PHImageManager defaultManager] requestAVAssetForVideo:videoAsset options:option resultHandler:^(AVAsset * _Nullable avasset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
Run Code Online (Sandbox Code Playgroud)
有同步方法吗?
谢谢.
每隔几个月,由于没有在块中使用弱自我,我得到了同样的问题,即ViewController没有被释放.有没有办法让Xcode警告我这个?
谢谢.
调用[self presentViewController]一个实例UIAlertController立即加载警报。有没有办法延迟它的呈现?
[self presentViewController:alert animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud) ios ×5
objective-c ×3
swift ×2
avasset ×1
cocoa ×1
cocoa-touch ×1
iphone ×1
memory-leaks ×1
retain-cycle ×1
video ×1