当前位置:   article > 正文

ios开发——Quartz坐标变化_ios quartz坐标

ios quartz坐标
  1. @implementation AppDelegate
  2. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  3. //创建根视图控制器
  4. ViewController* rootViewController = [[ViewController alloc] init];
  5. //创建自定义视图
  6. MyView* view = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  7. //用自定义视图替换系统默认视图
  8. rootViewController.view = view;
  9. self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  10. [self.window makeKeyAndVisible];
  11. self.window.rootViewController = rootViewController;
  12. return YES;
  13. }
  14. @end
  1. #import "MyView.h"
  2. @implementation MyView
  3. - (void)drawRect:(CGRect)rect {
  4. //填充白色背景
  5. [[UIColor whiteColor] setFill];
  6. UIRectFill(rect);
  7. //创建UIImage图片对象
  8. UIImage *uiImage = [UIImage imageNamed:@"cat"];
  9. //将UIImage图片对象转换为CGImage图片对象
  10. CGImageRef cgImage = uiImage.CGImage;
  11. CGContextRef context = UIGraphicsGetCurrentContext();
  12. CGContextScaleCTM(context, 1, -1);//变化坐标
  13. CGContextTranslateCTM(context, 0, -uiImage.size.height);//变化坐标
  14. CGRect imageRect = CGRectMake(0, 0, uiImage.size.width, uiImage.size.height);
  15. CGContextDrawImage(context, imageRect, cgImage);
  16. }
  17. @end

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/124987
推荐阅读
相关标签
  

闽ICP备14008679号