小编vai*_*hav的帖子

ARC中的引用计数

我在ARC引用计数方面有点混乱你可以告诉我下面的波纹管代码的参考数量.

var vc1 = UIViewController()
var vc2 = vc1
var vc3 = vc2
weak var vc4 = vc3
Run Code Online (Sandbox Code Playgroud)

问题是:

  • 引用计数vc1?
  • 引用计数vc2?
  • 引用计数vc3?
  • 引用计数vc4?

objective-c ios automatic-ref-counting swift

19
推荐指数
1
解决办法
3065
查看次数

解锁手机时,AVCapture预览会冻结/卡住

用物镜C编写的iOS相机应用程序在从锁定屏幕返回/解锁手机时冻结其预览图层.

正在调用所有摄像机配置设置viewWillAppear.到目前为止,我已经成功了,除了唯一的问题,即从锁定屏幕返回时相机预览图层冻结或卡住.我的代码的相机部分如下所示.

任何帮助深表感谢.谢谢.ps:请随意指出我的代码中的任何错误,因为我只是一个新手.

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    dispatch_async(dispatch_get_main_queue(), ^{
    [self setGUIBasedOnMode];
    });
}


-(void) setGUIBasedOnMode
{
if (![self isStreamStarted]) {
if (shutterActionMode == SnapCamSelectionModeLiveStream)
{
    _flashButton.hidden = true;
    _cameraButton.hidden = true;
    _liveSteamSession = [[VCSimpleSession alloc] initWithVideoSize:[[UIScreen mainScreen]bounds].size frameRate:30 bitrate:1000000 useInterfaceOrientation:YES];
    [_liveSteamSession.previewView removeFromSuperview];
    AVCaptureVideoPreviewLayer  *ptr;
    [_liveSteamSession getCameraPreviewLayer:(&ptr)];
    _liveSteamSession.previewView.frame = self.view.bounds;
    _liveSteamSession.delegate = self;
}
else{
    [_liveSteamSession.previewView removeFromSuperview];
    _liveSteamSession.delegate = nil;
    _cameraButton.hidden = false;
    if(flashFlag == 0){
        _flashButton.hidden = false;
    }
    else if(flashFlag == 1){
        _flashButton.hidden = true;
    } …
Run Code Online (Sandbox Code Playgroud)

objective-c ios avcapture avcapturesession

7
推荐指数
1
解决办法
862
查看次数

Xcode 8 Autocomplete Broken - 仅显示有限的用户代码片段 - 知道原因吗?

这才刚刚开始.Autocomplete一直工作得相当好,然后开始溅射,只显示autocomplete一些标准的Cocoa类/方法等.最好描述为周期性的奇怪遗漏.我正在使用Cocoa&Objective C但它似乎不仅仅是打破了Objective C.

我删除了派生数据,但没有效果.(默认是~/Library/Developer/Xcode/DerivedData但我喜欢保留在我的项目文件夹中以便于删除)

Xcode 是如此巨大(如操作系统)我在这里重新安装和阅读帖子犹豫不决,无论如何都无法正常工作.

它正在测试我对Cocoa方法和参数顺序的记忆......之前的生活autocomplete还可以,但我想把它还给...

xcode cocoa autocomplete objective-c xcode8

6
推荐指数
1
解决办法
735
查看次数

如何在 iOS 中添加 android like toast?

在android中我们可以直接添加toast。他们有什么方法可以在iOS中添加类似的吐司吗?

我创建了透明视图以用作吐司,但对于多种文本大小,我必须创建多个视图。

objective-c ios

5
推荐指数
1
解决办法
4742
查看次数

UIButton 平滑触摸效果

我正在尝试实现UIButton's平滑的触摸效果,就像我们在iPhone设备中使用计算器一样。但是我已经尝试了一些代码Objective c,并Swift为良好,但发现了同样的结果是达不到的欲望。

试过的代码:

@IBAction func someAction(sender: UIButton){
    button.setBackgroundColor(UIColor.blackColor(), forState: UIControlState.Highlighted)
}
Run Code Online (Sandbox Code Playgroud)
// using extension
extension UIButton {
    func setBackgroundColor(color: UIColor, forState: UIControlState) {
        UIGraphicsBeginImageContext(CGSize(width: 1, height: 1))
        CGContextSetFillColorWithColor(UIGraphicsGetCurrentContext(), color.CGColor)
        CGContextFillRect(UIGraphicsGetCurrentContext(), CGRect(x: 0, y: 0, width: 1, height: 1))
        let colorImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()

        self.setBackgroundImage(colorImage, forState: forState)
    }}
Run Code Online (Sandbox Code Playgroud)

说明:上面的代码可以正常工作,但应用的效果不是那么流畅。事实上,当我触摸按钮时,需要一纳秒的时间在其上应用背景图像,当我释放触摸时,背景图像突然消失。

我也在Objective cusingTouchUpInsideTouchDownevent 中尝试过这个,但结果发现相同。

谢谢你的时间。

objective-c uibutton ios swift

4
推荐指数
1
解决办法
6274
查看次数

选择其他单元格时,取消选择集合视图单元格

我有一个图像的细胞viewController,我想给用户一个选项来选择的一个image为他们title label.如何让他们只选择一个image,即如果他们选择另一个image我想取消选择image他们之前选择的.

这就是我做的:

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
            let cell = collectionView.cellForItem(at: indexPath)
            cell?.layer.borderWidth = 5.0
            cell?.layer.borderColor = UIColor.black.cgColor
            collectionView.allowsMultipleSelection = false
        }
Run Code Online (Sandbox Code Playgroud)

但它允许我选择所有细胞而不仅仅是我喜欢的一个细胞.

ios uicollectionview swift

3
推荐指数
1
解决办法
2436
查看次数

在导航标题下添加搜索栏

这是我的代码:

[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 500, 800)];
self.navigationItem.title = @"locations";
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, self.view.frame.size.width,110.0)];
UISearchBar *searchBar1 = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 40, 240, 34)];
[self.navigationController.view addSubview:searchBar1];
elf.navigationItem.title = @"locations";
//self.navigationItem.titleView = searchController.searchBar;
self.navigationController.navigationBar.barTintColor = `Color grayColor];
self.definesPresentationContext = YES;
Run Code Online (Sandbox Code Playgroud)

像那个屏幕截图

objective-c uinavigationcontroller uisearchbar ios

3
推荐指数
1
解决办法
5190
查看次数

具有 UIDocumentPickerModeOpen 模式的 UIDocumentPickerViewController 未授予在 xcode 中编辑文件的权限(iOS)

我希望用户从文件应用程序中选择一个文件,我必须读取该文件的内容,修改它并将其写入同一位置。

我试图使用以下代码打开该文件:

UIDocumentPickerViewController *documentProvider;
documentProvider = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[NSArray arrayWithObjects:@"public.comma-separated-values-text", nil] inMode: UIDocumentPickerModeOpen];
documentProvider.delegate = self;
documentProvider.modalPresentationStyle = UIModalPresentationOverFullScreen;
Run Code Online (Sandbox Code Playgroud)

委托功能:

- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url { NSLog(@"%@", url.absoluteString); }

但是当我尝试查看或编辑该文件时,它显示错误,表明我没有查看/写入权限。

我收到的 URL 是 file:///private/var/mobile/Library/Mobile%20Documents/com~apple~CloudDocs/filename.csv

有什么办法可以获取 iCloud 中文件的权限吗?我发现很少有第三方应用程序可以修改文件的内容。

iphone xcode objective-c ios

2
推荐指数
1
解决办法
2289
查看次数

UITableViewCell内存分配

我不确定使用或不使用内部方法的tableView内存分配过程。reuseIdentifier statictableView delegate

假设我们有 20 个从方法 method 返回的数组,那么每次调用方法时,在方法之后将在内存中分配numberOfRowsInSection多少个数组。cellcellForRowAtIndexPath[UITableViewCell alloc] alloc

示例代码:

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return 20;   // array count
}

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier]; 
        // how many cell will be alloc here
    }

// configure cell
}
Run Code Online (Sandbox Code Playgroud)

任何有用的澄清将不胜感激,感谢您的宝贵时间。

memory-management objective-c uitableview

1
推荐指数
1
解决办法
1463
查看次数

在Swift中收听InfowWindow点击

我知道有可能捕获标记的infowindow中的水龙头.我按照这里的文档.

所有都是写的,Objective C所以我尝试将其转换为Swift,这是我的代码:

func mapView(_ mapView: GMSMapView, didTap InfoWindowOfMarker: GMSMarker) {
        print("You tapped infowindow")

    }
Run Code Online (Sandbox Code Playgroud)

但这根本不会被解雇.这个方法有什么问题?

ios google-maps-sdk-ios swift

1
推荐指数
1
解决办法
2123
查看次数

是否可以在 CAKeyFrameAnimation 之后更新按钮的位置?

我一直在尝试在完成后更新按钮的位置CAKeyFrameAnimation。到目前为止,我已经在弧上的某个角度(最终角度)停止了动画,但是,按钮所进行的触摸似乎是在动画发生之前的那个点。

这是我一直在使用的代码:

for(int i = 0; i <numberOfButtons; i++)
{
    double angle = [[self.buttonsArray objectAtIndex:i] angle];

    if(angle != -50 && angle !=270){
        CGPoint arcStart = CGPointMake([[self.buttonsArray objectAtIndex:i] buttonForCricle].center.x, [[self.buttonsArray objectAtIndex:i] buttonForCricle].center.y);
        CGPoint arcCenter = CGPointMake(centerPoint.x, centerPoint.y);
        CGMutablePathRef arcPath = CGPathCreateMutable();
        CGPathMoveToPoint(arcPath, NULL, arcStart.x, arcStart.y);
        CGPathAddArc(arcPath, NULL, arcCenter.x, arcCenter.y, 150, ([[self.buttonsArray objectAtIndex:i] angle]*M_PI/180), (-50*M_PI/180), YES);
        UIButton *moveButton = (UIButton *)[self.view viewWithTag:i+1];
        CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        pathAnimation.calculationMode = kCAAnimationPaced;
        pathAnimation.fillMode = kCAFillModeForwards;
        // pathAnimation.values = @[@0];
        pathAnimation.removedOnCompletion = NO; …
Run Code Online (Sandbox Code Playgroud)

animation objective-c ios

1
推荐指数
1
解决办法
249
查看次数

重新加载后,在UITableView中保持单元格位置

我每隔几分钟刷新一次我的UITable,如果有新数据,它们应该在表的开头添加而不是重新加载.

var j = 0
let n = store?.news?.count
while(j < n!){
self.news?.insert((store?.news?[j])!, at: j)
    j = j + 1
}
Run Code Online (Sandbox Code Playgroud)

在第一个位置保存数据没问题.问题是我不能保持单元格位置在每次重新加载后向上移动(添加的记录数),我已经尝试了多个功能但显然它只适用于表格末尾添加的数据.

let contentOffset = self.tableV.contentOffset
self.tableV.reloadData()
self.tableV.contentOffset = contentOffset
Run Code Online (Sandbox Code Playgroud)

此外,我厌倦了保存单元格位置并添加输入数据的计数,但这种添加不起作用.有没有办法添加计数的输入数据的数量,让N对indexPath.row?

uitableview ios swift

0
推荐指数
1
解决办法
2877
查看次数

将图像从Objective VC发送到Swift配置的VC

我正在开发一个项目,某个地方需要ViewControler使用segue或storyboard 将编辑过的图像发送给另一个.

首先要了解一些要点.

  • ViewController我发送其使用配置的图像Objective C.
  • 并且图像将通过ViewController使用SwiftLang 配置的图像.

问题:

在Objective .m文件中导入的Swift类是不可见的,因此它允许我创建其对象以引用其成员.

我试过了:

// here i am not able to create SwiftVC class object so i can pass image further
SwfitVC *object = [self.storyboard instantiateViewControllerWithIdentifier:@"VC_Identifire"]; 
object.image = image; 
[self.navigationController pushViewController:object animated:YES];
Run Code Online (Sandbox Code Playgroud)

导入.m文件后,SwftVC类不可见.

请看看.谢谢.

iphone objective-c viewcontroller ios swift3

0
推荐指数
1
解决办法
81
查看次数