小编Ram*_*har的帖子

设置后NSLayoutConstraint常量不更新

我有一个UIView带有相应xib文件的子类.在我的xib中,我有一个NSLayoutConstraint属性,我正在尝试动画.我有一个animateIn方法.问题是只有animateIn方法有效.当我尝试再次更新常量时,它只是保持在前一个值.

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *horizontalConstraint;
Run Code Online (Sandbox Code Playgroud)

按下按钮后,我正在尝试更新常量.但是在设置之后,常量似乎没有更新.即使将其设置为-500,它仍然会记录0.我正在打电话layoutIfNeeded但没有任何反应.

// this works
- (void) animateIn { 
    [UIView animateWithDuration:1.0 delay:2.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.alpha = 1.0;
    } completion:^(BOOL finished) {

        [UIView animateWithDuration:1.0 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            self.horizontalConstraint.constant = 0;
            [self layoutIfNeeded];
        } completion:^(BOOL finished) {
        }];
    }];
}

// this does not work
- (IBAction)resume:(id)sender {
        self.horizontalConstraint.constant = -500;
        [self layoutIfNeeded];

        NSLog(@"%f",self.horizontalConstraint.constant); // this always stays 0
    }
Run Code Online (Sandbox Code Playgroud)

UPDATE

当我想第二次使用它时,我的NSLayoutConstraint似乎是(null).这可以解释为什么它没有更新.我应该如何保留它的参考?

objective-c uiviewanimation ios nslayoutconstraint

21
推荐指数
4
解决办法
3万
查看次数

如何将动画GIF分割成UIImages数组?

我需要对动画的各个帧进行一些处理,GIF所以我需要能够分割动画GIF,做一些处理并将它再次合并到一个GIF.

我知道如何从单独创建动画gif UIImages但我不知道如何将a的帧分割GIF成单独的UIImages.

有人可以分享一些可以做到这一点的代码吗?

objective-c animated-gif uiimage ios

12
推荐指数
2
解决办法
4810
查看次数

按比例调整UIImage然后裁剪

我正在使用此代码调整使用相机拍摄的图像的大小.我按比例缩小缩略图,但后来我想把它裁剪成60x60平方格式.我尝试合并:

CGImageRef imageRef = CGImageCreateWithImageInRect(CGImage, rect); 
Run Code Online (Sandbox Code Playgroud)

但我没有设法让它正常工作.我如何使用Core Graphics这样做?

- (UIImage *) resizeCapturedImage:(UIImage *) img toWidth:(float) w{

    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
    CGContextRef ctx = CGBitmapContextCreate(NULL,w,w, 8, 0, colorspace,kCGImageAlphaPremultipliedFirst);

    CGContextDrawImage(ctx, CGRectMake(0, 0, w,img.size.width*w/img.size.height), img.CGImage);
    CGImageRef thumb = CGBitmapContextCreateImage(ctx);
    UIImage *final = [UIImage imageWithCGImage:thumb scale:1.0 orientation:UIImageOrientationRight];

    return final;
}
Run Code Online (Sandbox Code Playgroud)

core-graphics objective-c uiimage ios

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

FHSTwitterEngine - 'NSInvalidArgumentException','data parameter is nil'

我正在使用FHSTwitterEngine将gif发布到twitpic.当我在iphone上有wifi或3G连接时,一切正常.但是我也希望在没有连接或上传失败时实现一些错误处理.因此,为了测试我将iphone置于飞行模式并尝试使用以下方法上传到twitpic:

id returned = [[FHSTwitterEngine sharedEngine] uploadImageToTwitPic:gif 
withMessage:@"message" twitPicAPIKey:@"key"];
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我立即得到以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'data parameter is nil'
Run Code Online (Sandbox Code Playgroud)

然后xcode指向FHSTwitterEngine框架中的这行代码:

 id parsedJSONResponse = removeNull([NSJSONSerialization JSONObjectWithData:responseData 
options:NSJSONReadingMutableContainers error:nil]);
Run Code Online (Sandbox Code Playgroud)

关于如何解决这个问题的任何想法?

objective-c twitpic ios nsjsonserialization fhs-twitter-engine

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

必须调用对非静态成员函数的引用

我有一个bars包含几个彩色框对象的向量.每个框对象都有自己的绘图和更新功能.每个盒子从屏幕的一侧移动到下一侧.当它在屏幕外时,应该移除该框.我正在使用迭代器移动框并确定它们何时在屏幕之外.

我对c ++很新,我无法让代码工作.从向量中擦除对象的功能给了我错误Reference to non static member function must be called.我正在阅读静态和非静态成员,但我仍然有点迷失.

这是我的主头文件及相关代码

class game : public ofxiPhoneApp {
    public:
    void setup();
    void update();
    void draw();
    void exit();

    vector <Colorbar> bars;
    bool checkBounds (Colorbar &b); 
};
Run Code Online (Sandbox Code Playgroud)

在我的game.mm文件中,我创建了矢量并迭代它以设置彩色条形对象的属性:

void game::setup(){
    bars.assign(5, Colorbar());
    for (int i = 0; i<bars.size(); i++) {
        ofColor color = colors.giveColor();
        bars[i].setup();
        bars[i].setColor(color.r,color.g,color.b);
        bars[i].setWidth(50);
        bars[i].setPos(ofGetScreenHeight()-(i*50), 0);
    }
}
Run Code Online (Sandbox Code Playgroud)

更新功能可在屏幕上移动条形图.

void game::update(){
    for(vector<Colorbar>::iterator b = bars.begin(); b != bars.end(); b++){
        (*b).update();
    }
    //this is the part …
Run Code Online (Sandbox Code Playgroud)

c++ opengl-es openframeworks

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

使用CIFilter围绕中心旋转CIImage

我正在尝试旋转CMSampleBuffer(来自相机)的像素数据并将其显示在UIImageView中.我不想旋转视图本身.它必须是实际的像素数据.

我抓住了Feed,将它转换为CIImage,然后用CIFilter旋转它.我在设置它必须旋转的点时遇到了麻烦.现在它围绕左下角旋转.我想围绕它的中心旋转它.

 func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputSampleBuffer sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {

            //create pixelbuffer

            let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)!
            let context = CIContext.init(options: nil)

            // calculating the radians to rotate the ciimage by
            let radians : Float = atan2f(Float(boxView!.transform.b), Float(boxView!.transform.a));
            //create ciimage from the pixelbuffer

            let options = [kCVPixelBufferCGImageCompatibilityKey as String: true,
                kCVPixelBufferCGBitmapContextCompatibilityKey as String: true,]
            let ci = CIImage.init(cvPixelBuffer: pixelBuffer, options: options)
            //transform filter
            let filter = CIFilter.init(name: "CIAffineTransform")
            //set translation point to center
            var transform = CGAffineTransform(translationX: self.view.frame.midX, …
Run Code Online (Sandbox Code Playgroud)

core-graphics ios cifilter ciimage swift3

0
推荐指数
2
解决办法
1929
查看次数